I have two array like this:
Array(
[0] => (
[id] => 1,
[order_id] => 1,
[image_url] => /resources/filename1
),
[1] => (
[id] => 2,
[order_id] => 1,
[image_url] => /resources/filename2
)
)
I want to merge imge_url
in single array because of order_id
, one order_id have multiple images.
I am expecting array like this:
Array(
[id] => 1,
[order_id] => 1,
[image_url] => (
[0] => "/resources/filename1",
[1] => "/resources/filename2"
)
)
Hope this will help you :
Working demo : https://eval.in/1014350
$array = array(array(
'id' => 1,
'order_id' => 1,
'image_url' => '/resources/filename1'
),array(
'id' => 2,
'order_id' => 1,
'image_url' => '/resources/filename2'
)
);
foreach ($array as $key => $item) {
if ($item['id'] == 1)
{
$data['id'] = $item['id'];
}
$data['order_id'] = $item['order_id'];
$data['image_url'][$key] = $item['image_url'];
}
print_r($data);
Program Output
Array
(
[id] => 1
[order_id] => 1
[image_url] => Array
(
[0] => /resources/filename1
[1] => /resources/filename2
)
)
Ok, I am sorry my previous answer was not right, this one does, I assume a couple of things:
Here is the code:
$arrays = [
[
"id" => 1,
"order_id" => 1,
"image_url" => "/resources/filename1"
],
[
"id" => 2,
"order_id" => 1,
"image_url" => "/resources/filename2"
],
[
"id" => 3,
"order_id" => 1,
"image_url" => "/resources/filename3"
],
[
"id" => 4,
"order_id" => 2,
"image_url" => "/resources/filename4"
],
];
foreach($arrays as $array) {
if(!isset($result[$array['order_id']]['id'])) {
$result[$array['order_id']]['id']=$array['id'];
}
$result[$array['order_id']]['order_id']=$array['order_id'];
$result[$array['order_id']]['image_url'][]=$array['image_url'];
}
print_r($result);
Tested here.
Firebase Cloud Functions: PubSub, "res.on is not a function"
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
Please help meI have 3 tables, all records of my elements table must have a complete interval
I am trying to make a text game in PHP but i have problem since i am programing in php for few daysI need to call function attack (I need $_mainAttack since it is combination of $_baseAttack and special attack) from defend function so i can calculate...
I have published a website for a friend and customer who sells products for children
There is a server with such parameters: