★ wanayoo — archive 1999 http://www.php.net/manual/hu/function.array.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Tömbök
Quick Reference
English version of this pageGerman version of this pageJapanese version of this pageItalian version of this pageFrench version of this page
Tömbök
* array
* array_count_values
* array_diff
* array_flip
* array_intersect
* array_keys
* array_merge
* array_merge_recursive
* array_multisort
* array_pad
* array_pop
* array_push
* array_rand
* array_reverse
* array_shift
* array_slice
* array_splice
* array_unique
* array_unshift
* array_values
* array_walk
* arsort
* asort
* compact
* count
* current
* each
* end
* extract
* in_array
* key
* krsort
* ksort
* list
* next
* pos
* prev
* range
* reset
* rsort
* shuffle
* sizeof
* sort
* uasort
* uksort
* usort
Manual: array
View the source code for this pageSearch the site



Previous page
 Tömbök
 Updated
Sat, 12 Aug 2000
array_count_values 
Next page


array

(unknown)

array --  Create an array

Description

array array ([mixed ...])

Returns an array of the parameters. The parameters can be given an index with the => operator.

Megjegyzés: Array() is a language construct used to represent literal arrays, and not a regular function.

The following example demonstrates how to create a two-dimensional array, how to specify keys for associative arrays, and how to skip-and-continue numeric indices in normal arrays.

Példa 1. Array() example


$fruits = array (
    "fruits"  => array ("a"=>"orange", "b"=>"banana", "c"=>"apple"),
    "numbers" => array (1, 2, 3, 4, 5, 6),
    "holes"   => array ("first", 5 => "second", "third")
);
      

See also: list().


User Contributed Notes: array


chopin@csone.kaist.ac.kr
25-Aug-1999 09:36
I wonder how associative array is implemented. I guess that it is based on hash function reference technique. It will be better in using this array facility if this manual notes the associative array implementation mechanism since execution speed is highly dependant to it.


baghera@mindspring.com
12-Oct-1999 02:54
Every array has an "internal pointer". When you create an array, the internal pointer is automatically set to point at the first member. You can print the current location of the pointer:

<pre>
$bob= current($myarrayname);
echo "$bob";
</pre>

You can advance the pointer to the next spot using next($myarrayname).

To see a particular member of an array, set a $variable= $myarrayname[2] where "2" is the number of the member you want to use.

When assigning members to an array, the members are numbered beginning with 0, rather than 1.



marce@compu-art.com.ar
24-Jan-2000 01:32
Cuando se crea un vector no es necesario agregar los numeros de indice.
ejemplo:
$mi_vector=array ("DOMINGO",0000,0000);



bigdan@kreft.net
30-Jan-2000 01:50
Displaying all data in a two-dimensional array is actually pretty simple:
<PRE>
<?
$users = array(
"djuan" => array(
"firstname" => "Don",
"lastname" => "Juan",
"age" => "102",
"weight" => "100"
),

"jordan23" => array(
"firstname" => "Michael",
"lastname" => "Jordan",
"age" => "36",
"weight" => "225"
)
);

/* Now print out the contents of the array. */

while ( list($username, $subarray) = each($users) ) {
echo "Username: $username: ";
echo "<ul>";

while ( list($key, $val) = each($subarray) ) {
echo "<li>$key : $val\n";
}

echo "</ul>";
}

?>

This will print out (assuming you're using a browser and not your shell):

Username: djuan:

firstname : Don
lastname : Juan
age : 102
weight : 100

Username: jordan23:

firstname : Michael
lastname : Jordan
age : 36
weight : 225
</PRE>



jakob.voss@s1999.tu-chemnitz.de
06-Feb-2000 10:47
I use this to completely display the content of an array:
<pre>
function print_array($array) {
if(gettype($array)=="array") {
echo "<ul>";
while (list($index, $subarray) = each($array) ) {
echo "<li>$index <code>=&gt;</code> ";
print_array($subarray);
echo "</li>";
}
echo "</ul>";
} else echo $array;
}
</pre>



ieure@uswest.net
29-Feb-2000 07:11
Arrays of objects is supposed to sneak into 4.0 final, and may already be in the betas.


php-manual@improbable.org
02-Apr-2000 03:17
If you want to create an array of a set size and you have PHP4, use array_pad(array(), $SIZE, $INITIAL_VALUE); This can be handy if you wish to initialize a bunch of variables at once:

list($Var1, $Var2, etc) = array_pad(array(), $NUMBER_OF_VARS, $INITIAL_VALUE);



sipiyou@t50.de
30-Apr-2000 04:56
the following code will allow you to generate an array on the fly,

$record = array ("item1" => "whatever");
$record["item2"]="something";

SiPiYou



caspre@yahoo.com
15-Jul-2000 05:20
I think that the way they explain the use of arrays is very bad. A much easier way to think about it is to compare with standard arrays in C. You can declare an array like: $array = array() and then just add items to it using syntax: $array[1] = 'poo'; for two dim arrays, use $array = array(array()), and reference using $array[x][x]. Much simpler...


csalvador@pangeatech.com
25-Jul-2000 01:57
To pass an array to another script, try serializing the array, then urlencoding the serialized value. Pass the array to the new script, then unserialize it to access it's contents. Check out Serialize and Unserialize for more info.


innuedo@...
25-Jul-2000 02:09
size of an array without using a while loop:
sizeof()



bianchi@vermontel.net
12-Aug-2000 04:01
An array of objects in version 3.

var userlist;
$user = new User();
$user->fillFromRow($row);
userlist[$ctr] = $user;
$firstuser = (Object) userlist[0];



 About Notes


Previous page
 Tömbök
 Updated
Sat, 12 Aug 2000
array_count_values 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.