Switch two items in associative array

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

Example:

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


        
17条回答
  •  借酒劲吻你
    2021-02-05 13:03

    yeah I agree with Lex, if you are using an associative array to hold data, why not using your logic handle how they are accessed instead of depending on how they are arranged in the array.

    If you really wanted to make sure they were in a correct order, trying creating fruit objects and then put them in a normal array.

提交回复
热议问题