PHP/Data Structure/array values
Содержание
array_values() function returns an array containing all of the values constituting the input array.
//Its syntax is: array array_values(array array)
<?
$great_wines = array ("A" => "a","Q" => "q","E" => "e");
$great_labels = array_values($great_wines);
print_r($great_labels) ;
?>
array_values( ) returns an array of all the values in that array
<?
$words = array("Hello", "World", "Foo", "Bar", "Baz");
var_dump($words);
asort($words);
var_dump($words);
var_dump(array_values($words));
?>
Getting and Displaying Counts of Array Values
<html>
<head>
<script type="text/javascript">
</script>
</head>
<body>
<?php
$countries = array( "USA" => "English", "Spain" => "Spanish",
"France" => "French", "Argentina" => "Spanish");
$languages = array_values($countries);
$language_count = array();
foreach($languages as $language)
if(!isset($language_count[$language]))
$language_count[$language] = 1;
else
$language_count[$language]++;
?>
<table>
<tbody>
<tr><th>Language</th><th>Number<br />of<br />Countries</th></tr>
<?php
foreach($language_count as $language => $number)
print "<tr><td>$language</td><td>$number</td></tr>\n";
?>
</tbody>
</table>
</body>
</html>
Return all the values of an array
<?
$array = array("size" => "XL", "color" => "gold");
array_values($array);
?>