我整天都在打破这个问题。 我正在使用Web服务,一旦我可以以一种方式取回阵列,或者我以不同的方式取回它。 所以我有一个功能可以剥离和提取数据。
这是功能。
function Detail($a){
$age= array();
$countArray = arrayCount($a);
if ($countArray == 1){
array_push ($age,
array(
"Name"=>$a['Name'],
"ProductReference"=>$a['ProductReference'],
"AdicRange"=>$a['AdicRange'],
"Pages"=>$s['Pages']
);
}elseif($countArray >= 2){
foreach ($a as $key => $d) {
array_push ($age,
array(
"Name"=>$d['Name'],
"ProductReference"=>$d['ProductReference'],
"AdicRange"=>$d['AdicRange'],
"Pages"=>$d['Pages']
) );
}
}else{
}
return $age;
}
我正在尝试添加到数组但是我让数组恢复不正确。 这是我回来的数组。
Array
(
[0] => Array
(
)
[1] => Array
(
[0] => Array
(
[Name] => 21X29 booklet Ver
[ProductReference] => DF0754(A4)
[AdicRange] => 4
[Pages] => 24
)
[1] => Array
(
[Name] => pro book 35X35
[ProductReference] => FM8774
[AdicRange] => 2
[Pages] => 20
)
[2] => Array
(
[Name] => pro book 26X10
[ProductReference] => FM1032
[AdicRange] => 2
[Pages] => 20
)
[3] => Array
(
[Name] => 21X29 booklet Hor
[ProductReference] => DF0750
[AdicRange] => 4
[Pages] => 24
)
[4] => Array
(
[Name] => pro book 35X35
[ProductReference] => FM8755
[AdicRange] => 2
[Pages] => 20
)
[5] => Array
(
[Name] => pro book 38X76
[ProductReference] => FM0099
[AdicRange] => 2
[Pages] => 50
)
[6] => Array
(
[Name] => pro book 40X80
[ProductReference] => FM7291
[AdicRange] => 2
[Pages] => 20
)
[7] => Array
(
[Name] => pro book 30X80
[ProductReference] => FM0058
[AdicRange] => 2
[Pages] => 20
)
[8] => Array
(
[Name] => pro book 20X60
[ProductReference] => FM1065
[AdicRange] => 2
[Pages] => 20
)
)
)
有人可以帮助我。
我正试图让这个阵列回来。
Array
(
[0] => Array
(
[0] => Array
(
[Name] => pro book 40X80
[ProductReference] => FM7291
[AdicRange] => 2
[Pages] =>
)
)
[1] => Array
(
[0] => Array
(
[Name] => 21X29 booklet Ver
[ProductReference] => DF0754(A4)
[AdicRange] => 4
[Pages] => 24
)
[1] => Array
(
[Name] => pro book 35X35
[ProductReference] => FM8774
[AdicRange] => 2
[Pages] => 20
)
[2] => Array
(
[Name] => pro book 26X10
[ProductReference] => FM1032
[AdicRange] => 2
[Pages] => 20
)
[3] => Array
(
[Name] => 21X29 booklet Hor
[ProductReference] => DF0750
[AdicRange] => 4
[Pages] => 24
)
[4] => Array
(
[Name] => pro book 35X35
[ProductReference] => FM8755
[AdicRange] => 2
[Pages] => 20
)
[5] => Array
(
[Name] => pro book 38X76
[ProductReference] => FM0099
[AdicRange] => 2
[Pages] => 50
)
[6] => Array
(
[Name] => pro book 40X80
[ProductReference] => FM7291
[AdicRange] => 2
[Pages] => 20
)
[7] => Array
(
[Name] => pro book 30X80
[ProductReference] => FM0058
[AdicRange] => 2
[Pages] => 20
)
[8] => Array
(
[Name] => pro book 20X60
[ProductReference] => FM1065
[AdicRange] => 2
[Pages] => 20
)
[9] => Array
(
[Name] => pro book 40X80
[ProductReference] => FM7291
[AdicRange] => 2
[Pages] =>
)
)
)
答案 0 :(得分:0)
您在第一个if子句中缺少右括号。
function Detail($a) {
$age = array();
$countArray = arrayCount($a);
if ($countArray == 0) {
array_push ($age,
array(
"Name" => $a['Name'],
"ProductReference" => $a['ProductReference'],
"AdicRange" => $a['AdicRange'],
"Pages" => $s['Pages']
));
} elseif ($countArray >= 1) {
foreach ($a as $key => $d) {
array_push($age, array(
"Name" => $d['Name'],
"ProductReference" => $d['ProductReference'],
"AdicRange" => $d['AdicRange'],
"Pages" => $d['Pages']
));
}
} else {
}
return $age;
}