Start with the keys, example $quy is your array
$keys = array_keys($quy);
for ($i = 0; $i < count($quy); $i++) {
foreach ($quy[$i] as $key => $value) {
// here work out what you need to do
Can take some trial and error.
I have the given array
array:7 [▼
"data" => "data"
"id_1553539135251" => "<p>nsmn</p>"
"about" => "about"
"id_1553539141598" => "<p>uiu</p>"
i need to convert this associative array into a 2 dimentional array like the exsample below
array:3 [▼
"id_1553539135251" => array:1 [▼
"content" => "<p>nsmn</p>"
"header" => "data"
]
"id_1553539141598" => array:1 [▼
"content" => "<p>uiu</p>"
"header" => "about"
]
]
My current code seems to be missing some logic but i can quite figure out the desired result.
$data = $request->all();
$json = array();
foreach($data as $key => $value){
if(strpos($key, 'id') !== false){
$json[$key]['content'] = $value;
}
}
my current code returns an array but not in the correct format my overall question is how would i go about converting the associative array in example one to the layout of example two with dynamic data
Please or to participate in this conversation.