<?php /** * php array get key by value * php數組根據值獲取鍵名 * @author http:// */ $items = array( "banana" => "fruit", "tomato" => "vegetable", "lentil" => "bean", "apple" => "vegetable" ); //1.返回一個鍵名,如果值有重復返回第一個鍵名 $key = array_search('vegetable', $items); echo $key; //tomato //2.返回多個鍵名 $keys = array_keys($items, 'vegetable'); print_r($keys); /* Array ( [0] => tomato [1] => apple ) */ ?>*