Convert an associative array to a simple array of its values in php

后端 未结 3 599
北海茫月
北海茫月 2020-11-28 10:02

I would like to convert the array:

Array ( 
[category] => category 
[post_tag] => post_tag 
[nav_menu] => nav_menu 
[link_category] => link_categ         


        
相关标签:
3条回答
  • 2020-11-28 10:40

    You should use the array_values() function.

    0 讨论(0)
  • 2020-11-28 10:40

    create a new array, use a foreach loop in PHP to copy all the values from associative array into a simple array

          $data=Array(); //associative array
    
          $simple_array = array(); //simple array
    
          foreach($data as $d)
          {
                $simple_array[]=$d['value_name'];   
          }
    
    0 讨论(0)
  • 2020-11-28 11:04

    simply use array_values function:

    $array = array_values($array);
    
    0 讨论(0)
提交回复
热议问题