Why is the restructured array subscript always the first? & Lt ;? Php $ id & nbsp; array (8, 31, 32); $ resarr & nbsp; array (); foreach ($ id & nbsp; as & nbsp; $ num) {$ product & nbsp; array (the pid array uses subscript to restructure the array. why is the restructured array subscript always the first?
$ Id = array (8, 31, 32 );
$ Resarr = array ();
Foreach ($ id as $ num)
{
$ Product = array (
Array (
'Pid '=> '10 ',
'Name' => 'product 1'
),
Array (
'Pid '=> '11 ',
'Name' => 'product 2'
)
);
Foreach ($ product as $ key => $ value)
{
$ Result_value = "";
Foreach ($ value as $ k => $ v)
{
$ Result_value. = $ result_value? "| ":"";
$ Result_value. = $ v ['pid'];
}
$ Product [$ key] ['value'] = $ result_value;
}
$ Resarr [$ num] = $ product;
Var_dump ($ resarr );
Echo"
";
}
Var_dump () always returns the subscript [8... Where is the error?
------ Solution --------------------
Print out the loop
------ Solution --------------------
$ Id = array (8, 31, 32 );
$ Resarr = array ();
Foreach ($ id as $ num)
{
$ Product = array (
Array (
'Pid '=> '10 ',
'Name' => 'product 1'
),
Array (
'Pid '=> '11 ',
'Name' => 'product 2'
)
);
Foreach ($ product as $ key => $ value)
{
$ Result_value = "";
Foreach ($ value as $ k => $ v)
{
$ Result_value. = $ result_value? "
------ Solution --------------------
":"";
$ Result_value. = $ v ['pid'];
}
$ Product [$ key] ['value'] = $ result_value;
}
$ Resarr [$ num] = $ product;
}
Var_dump ($ resarr );
Echo"
";