I am having some trouble creating an array in PHP, I am pulling data from a JSON file creating an array with it to post.
I can't quite figure out why this foreach loop will not work. I can't see an apparent syntax error in my code.
Error :
PHP Syntax Check: Parse error: syntax error, unexpected 'foreach' (T_FOREACH), expecting ')' in your code on line 4 foreach($w['order']['something'] as $field => $value) {
I have an array created without the foreach loop and it appears to work fine (below).
"Items" => array(
array(
"l_ref" => "888",
"sku" => "888",
"qty" => "QTY",
"typ" => "4",
"job_ref" => "3929"
),
array(
"l_ref" => "888",
"sku" => "1323"
)
)
Here is the code that doesn't work with the foreach loop present. Is there anything obvious I am missing?
$orderData = array (
"Order" => array(
"Items" => array(
foreach($w['order']['something'] as $field => $value) {
if ($value['something'][1]['name'] == "id") {
array(
"something" => "something"
)
}
}
)
)
)
I am expecting the code to loop and pull out items based on a certain value.
Error: PHP Syntax Check: Parse error: syntax error, unexpected 'foreach' (T_FOREACH), expecting ')' in your code on line 4 foreach($w['order']['something'] as $field => $value) {