7/10/2016

PHP : หาค่าที่มากที่สุด ใน Array และเอาตำแหน่ง มาใช้งานต่อ

PHP : หาค่าที่มากที่สุด ใน Array และเอาตำแหน่ง มาใช้งานต่อ

array_search — Searches the array for a given value and returns the corresponding key if successful

Description
mixed array_search ( mixed $needle , array $haystack [, bool $strict = false ] )

http://php.net/manual/en/function.array-search.php

ตัวอย่าง
Array
$Style = array(1 => $Perfectionist, 2 => $Giver, 3 => $Performer, 4 => $TragicRomantic, 5 => $Observer, 6 => $Questioner, 7 => $Epicure, 8 => $Protector, 9 => $Peacemaker);

หาค่าที่มากที่สุด และ Search หาตำแหน่ง ของค่าที่จะเอาไปแสดง เช่น ตัวอย่างจะเอา ตำแหน่งที่ 1-9 ไปใช้

$StyleMax = array_search(max($Style), $Style);


ตัวอย่างดูได้จากไฟล์ Intranet
enneagram\result_view.php

No comments:

Post a Comment