다차원 배열에 대해서 질문 드립니다...
본문
$str="253020|253020,1.62,3.28,3.44|AAA|1|1.62////253004|253004,1.62,3.28,3.44|AAA|2|3.44////252988|252988,2.00,3.28,3.44|AAA|1|2.00////252972|252972,1.62,3.52,5.02|AAA|2|5.02";
$str_arr=explode("////",$str);
$if_num=count($str_arr)-1;
for ($k=0; $k<=eval[if_num()]; $k++) {
$str_arr1[$k]=explode("|",str_arr[$k]);
echo "<br>";
for ($i=0; $i<=4; $i++) {
$test=$str_arr1[$k][$i]."<br>";
echo $test;
}
}
결과가
253020
253020,1.62,3.28,3.44
AAA
1
1.62
253004
253004,1.62,3.28,3.44
AAA
2
3.44
252988
252988,2.00,3.28,3.44
AAA
1
2.00
252972
252972,1.62,3.52,5.02
AAA
2
5.02
어떻게 해야 결과물이
a = "253020, 253004, 252988, 252972"
b = "1, 2, 1, 2"
c = "1.62, 3.44, 2, 5.02"
d = "AAA"
e = "1.62, 1.62, 2, 1.62"
f = "3.28, 3.28, 3.28, 3.52"
g = "3.44, 3.44, 3.44, 5.02"
이런식으로 나올지 도저히 감히 잡히질 않네요..
작은 힌트라도 부탁드립니다..ㅠㅠ
!-->답변 2
<?php
$str = '253020|253020,1.62,3.28,3.44|AAA|1|1.62////253004|253004,1.62,3.28,3.44|AAA|2|3.44////252988|252988,2.00,3.28,3.44|AAA|1|2.00////252972|252972,1.62,3.52,5.02|AAA|2|5.02';
$arr = explode('////', str_replace(',', '|', $str));
$cnt = count($arr);
for ($i = 0; $i < $cnt; $i++) {
$arr2 = explode('|', $arr[$i]);
list($a0[], $a1[], $a2[], $a3[], $a4[], $a5[], $a6[], $a7[], $a8[]) = $arr2;
}
echo 'a = '.implode(',', $a1);
echo '<br>';
echo 'b = '.implode(',', $a6);
echo '<br>';
echo 'c = '.implode(',', $a4);
echo '<br>';
echo 'd = '.$a5[0];
echo '<br>';
echo 'e = '.implode(',', $a2);
echo '<br>';
echo 'f = '.implode(',', $a3);
echo '<br>';
echo 'g = '.implode(',', $a7);
echo '<br>';
!-->
감사합니다.. (__)
답변을 작성하시기 전에 로그인 해주세요.