Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Indexed Multidimensional Array to Multidimensional Array with Key Value pair 3

Status
Not open for further replies.

waubain

Technical User
Dec 13, 2011
200
US
I have an indexed array like this
Code:
Array ( 
[0] => Array ( 
	[0] => 2021-07-06_18-00.jpg 
	[1] => Tuesday Jul 06, 2021, 6:00 pm ) 
[1] => Array ( 
	[0] => 2021-07-05_12-00.jpg 
	[1] => Monday Jul 05, 2021, 12:00 pm ) 
[2] => Array ( 
	[0] => 2021-07-04_12-00.jpg 
	[1] => Sunday Jul 04, 2021, 12:00 pm ) 
[3] => Array ( 
	[0] => 2021-07-03_12-00.jpg 
	[1] => Saturday Jul 03, 2021, 12:00 pm ) )

and I need to change the index to a key so it looks like this:
Code:
array(
    array(
        "imgname" => "2021-07-06_18-00.jpg",
        "imgdate" => "Tuesday Jul 06, 2021, 6:00 pm",
    ),
    array(
        "imgname" => "2021-07-05_12-00.jpg",
        "imgdate" => "Monday Jul 05, 2021, 12:00 pm",
    ),
    array(
        "name" => "2021-07-04_12-00.jpg",
        "email" => "Sunday Jul 04, 2021, 12:00 pm",
    )

I tried array_combine and array_column, but I do not think my syntax was correct. Thank you.
 
Hi

Like this ?
Code:
[COLOR=orange]array_walk[/color][teal]([/teal][navy]$yourArray[/navy][teal],[/teal] [b]function[/b][teal](&[/teal][navy]$image[/navy][teal]) {[/teal] [navy]$image[/navy] [teal]=[/teal] [COLOR=orange]array_combine[/color][teal]([[/teal][i][green]'imgname'[/green][/i][teal],[/teal] [i][green]'imgdate'[/green][/i][teal]],[/teal] [navy]$image[/navy][teal]); });[/teal]


Feherke.
feherke.github.io
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top