php - How to write this array in loop? -


how write array in loop?

 $columns = array(         "name" => 'slider'         , "value" => $user_slider,         "name" => 'welcomebox'         , "value" => $user_welcomebox,         "name" => 'servicebox'         , "value" => $user_servicebox,         "name" => 'postbox'         , "value" => $user_postbox      ); 

how write name , value in loop?

your array wrong. mean sub array's. change array, so:

 $columns = [     [         'name' => 'slider',         'value' => $user_slider     ],     [         'name' => 'welcomebox',         'value' => $user_welcomebox     ],     [        'name' => 'servicebox',        'value' => $user_servicebox     ],     [         'name' => 'postbox',         'value' => $user_postbox     ] ]; 

so can loop foreach:

foreach ($columns $key => $value) {     echo $key . ': ' . $value . '<br>'; } 

Comments