ADD key and value into the end of array php
$array1 = Array
(
[0] => Array
(
[id] => 9
[item_id] => 10486
[name] => brief-about-youself
)
[1] => Array
(
[id] => 10
[item_id] => 10486
[name] => what-is-your-aim
)
[2] => Array
(
[id] => 11
[item_id] => 10486
[name] => how-would-you-rate-the-ease-of-registration
)
[3] => Array
(
[id] => 12
[item_id] => 10486
[name] => enter-your-date-of-birth
)
)
$array2 =
Array
(
[0] => Array
(
[id] => 1
[question_id] => 9
[answer] => You have no changed Love it are you maxim ?
)
[1] => Array
(
[id] => 3
[question_id] => 11
[answer] => 9
)
)
I want to push array1 to Array2
It should insert get_answer key to the each element if $array1 id match with $array2 question_id
ADD key and value into the end of array php. Thank you for your effort please guide. I work around but does not work
foreach($question as $key=>$value){
if(isset($value['get_answer']) && $value['get_answer']['updated_by'] == $user_id){
$question[$key]['answer'] = $value['get_answer']['answer'];
unset($question[$key]['get_answer']);
}
}
from Laravel Questions and Answers https://laravelquestions.com/php/add-key-and-value-into-the-end-of-array-php/
via Lzo Media
No comments:
Post a Comment