Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

geetpurwar's avatar

Php Query

Hi everyone,

This query is regarding Php: Is there anyway we can convert Array A to Array B:

Please advise. Thanks.

Array A:

array:9 [▼
  "color_content" => "zinc-400"
  "color_headline" => "zinc-300"
  "color_stroke" => "#d4d4d8"
  "image_logo" => "https://bannertize.com/image/pushvertize.svg"
  "image_main" => "https://images.unsplash.com/photo-1609790026016-54ace8b92d81?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1825&q=80"
  "text_background" => "01"
  "text_content" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit ame. Read More »"
  "text_headline" => "Design"
  "text_topline" => "Black Mirror"
]

Array B:

array:3 [▼
  0 => array:4 [▶
    "layer" => "color"
    "content" => "zinc-400"
    "headline" => "zinc-300"
    "stroke" => "#d4d4d8"
  ]
  1 => array:3 [▶
    "layer" => "image"
    "logo" => "https://bannertize.com/image/pushvertize.svg"
    "main" => "https://images.unsplash.com/photo-1609790026016-54ace8b92d81?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1825&q=80"
  ]
  2 => array:5 [▶
    "layer" => "text"
    "background" => "01"
    "content" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit ame. Read More »"
    "headline" => "Design"
    "topline" => "Black Mirror"
  ]
]
0 likes
4 replies
Snapey's avatar

not automatically

You can hard code it

$out = [
		['layer' => 'color', 
         'content' => $in['color_content'],
         'headline' => $in['color_headline'],
         'stroke'=>$in['color_stroke']
         ],[
          'layer'=>'image',
          'logo' => $in['image_logo'],
// etc etc
]
Sinnbeck's avatar

You can, but you need to specify all keys manually

Please or to participate in this conversation.