Switch two items in associative array

后端 未结 17 2174
自闭症患者
自闭症患者 2021-02-05 12:53

Example:

$arr = array(
  \'apple\'      => \'sweet\',
  \'grapefruit\' => \'bitter\',
  \'pear\'       => \'tasty\',
  \'banana\'     => \'yellow\'
)         


        
17条回答
  •  Happy的楠姐
    2021-02-05 13:21

    if the array comes from the db, add a sort_order field so you can always be sure in what order the elements are in the array.

提交回复
热议问题