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

PHP Home Page

Manual Table of Contents
Up to Guida Funzioni
Quick Reference
English version of this pageGerman version of this pageJapanese version of this pageFrench version of this pageHungarian version of this page
Guida Funzioni
* Apache
* Arrays
* Aspell
* BC math
* Calendar
* COM
* Classes/Objects
* ClibPDF
* CURL
* Cybercash
* dba
* Date/time
* dBase
* DBM
* Directories
* Dyn.loading
* DOM XML
* filePro
* Filesystem
* FDF
* FTP
* gettext
* HTTP
* Hyperwave
* ICAP
* Graphics
* IMAP
* Informix
* InterBase
* LDAP
* Mail
* Mat.
* MCAL
* mcrypt
* mhash
* MS SQL Server
* Misc.
* mSQL
* MySQL
* Network
* ODBC
* Oracle
* OCI8
* PDF
* Verisign Payflow Pro
* PHP options/info
* POSIX
* PostgreSQL
* Program Execution
* Pspell
* Recode
* PCRE
* Regexps
* Semaphore
* Sessions
* SWF
* SNMP
* Strings
* Sybase
* URLs
* Variabili
* Vmailmgr
* WDDX
* XML
* NIS
* Zlib
Manual: Array functions
View the source code for this pageSearch the site



Previous page
 virtual
 Updated
Sun, 06 Aug 2000
array 
Next page


II. Array functions

Sommario
array — Create an array
array_count_values — Counts all the values of an array
array_flip — Flip all the values of an array
array_keys — Return all the keys of an array
array_merge — Merge two or more arrays
array_pad — Pad array to the specified length with a value
array_pop — Pop the element off the end of array
array_push — Push one or more elements onto the end of array
array_reverse — Return an array with elements in reverse order
array_shift — Pop an element off the beginning of array
array_slice — Extract a slice of the array
array_splice — Remove a portion of the array and replace it with something else
array_unshift — Push one or more elements onto the beginning of array
array_values — Return all the values of an array
array_walk — Apply a user function to every member of an array.
arsort — Sort an array in reverse order and maintain index association
asort — Sort an array and maintain index association
compact — Create array containing variables and their values
count — count elements in a variable
current — Return the current element in an array
each — Return the next key and value pair from an array
end — Set the internal pointer of an array to its last element
extract — Import variables into the symbol table from an array
in_array — Return true if a value exists in an array
key — Fetch a key from an associative array
krsort — Sort an array by key in reverse order
ksort — Sort an array by key
list — Assign variables as if they were an array
next — Advance the internal array pointer of an array
pos — Get the current element from an array
prev — Rewind the internal array pointer
range — Create an array containing a range of integers
reset — Set the internal pointer of an array to its first element
rsort — Sort an array in reverse order
shuffle — Shuffle an array
sizeof — Get the number of elements in an array
sort — Sort an array
uasort — Sort an array with a user-defined comparison function and maintain index association
uksort — Sort an array by keys using a user-defined comparison function
usort — Sort an array by values using a user-defined comparison function

User Contributed Notes: Array functions


david@preform.dk
31-Jan-1999 06:30
use the max function to get the highest value of an array e.g:
$maxval = max($array);



dmarsh@spscc.ctc.edu
30-Mar-1999 04:18
Also see the 'Variable' section (http://www.php3.org/manual/ref.var.php3) for useful functions (like unset to destroy a variable or element in an array).


r.eckart@upw.de
09-Sep-1999 09:52
It seems to be impossible to write into multidimensional arrays using HTML posts, like:
<PRE>
&lt;select name="thisarray[0][]" size="1" &gt;
&lt;option value="1" &gt;Foo
&lt;option value="2" &gt;Bar
&lt;option value="3" &gt;Blub
&lt;/select&gt;
</PRE>
It is possible though to access a specific array position e.g. thisarray[1].
I think it might be useful if multidimensional access would be added.



shevek@anarres.org
11-Feb-2000 06:45
The two essential array functions are
filter and map.

We have map (array_walk).

Can we have filter (see 'grep' in Perl) please?

Is there any other nice way to walk an array and remove items based on some sort of 'validity'?

S.



javier@eos.com.pe
24-Apr-2000 12:41
is there any way to get the _whole_ array using <PRE>next()</PRE> ?
this code would skip the first item:
<PRE>
reset ($arr);
while ($item = next ($arr)) {
//.... do something with $item
}
</PRE>
the problem is that next() preincrements the counter (linke ++p, instead of p++)
i think reset() should go to 'one before' the first item.



sheppard_norfleet@mail.crc.com
28-Apr-2000 05:47
It would be very helpful if there were two additionaly array functions (ar_import,ar_export) that would take any array and encode it(ar_export) into a string so it could be passed via a form, or some other array insensitive transport.

Then, when the encoded string was received it could be decoded back to an array.(ar_import).



jbarrett@iplay,net
30-Apr-2000 03:02
Check out Serialize and Unserialize


bjorn@kulturkonsult.no
04-May-2000 07:57
I want a function to return a two-dimensional array, containing the parsed contents of a text file. The format of the text file is:

<pre>username,f34d76asd6542hfg54387634
username2,d8937f98f73987fkjs3498
</pre>

I want the array to be something like

$userdb[0][user] = username

$userdb[0][pass_hash] = f34d76as...

The number of lines may change. I guess that file() and explode() is the clue. And, yes, it must work in PHP 3.
Any ideas would be greatly appreciated.



bjorn@kulturkonsult.no
04-May-2000 12:42
Well, my earlier post regarding two-dimensional arrays weren't supposed to be here in the first place - I realized that later. Anyway, I were able to figure it all out myself. Here's the solution, if anyone's interested:
<pre>
function Users2array() {
$f = fopen("./userdb", "r");
$i = -1;
while (!feof($f)) {
$i++;
$user = explode(",", fgets($f, 4096));
$db[$i]["user"] = $user[0];
$db[$i]["hash"] = trim($user[1]);
}
return $db;
}
</pre>



terry@terrym.com
08-May-2000 11:53
<pre>
There is no mention of "is_array()" on this page.

This is the logical place where some one would look for such a thing, so it should be here.

There is mention of it via the "count()" page in the "See also" section, but it should be here also.

While it is great to have the "veriable functions" section, one who does not know their way around
the documentation is likely to bang head for hours before finding some of this stuff that is in logical,
but non-intuative places.

I guess that what I'm trying to say here is that when the "logical" placement of something is
"non-intuative", there should be a cross link in the place that one would intuatively look in.

Terry
</pre>



jimo@crusade.org
24-May-2000 07:19
How to get array values from a form without using []?
Professional PHP Programming, page 163, suggests that when you have text boxes with the same name, put [] after them, eg:
<INPUT TYPE="text" NAME="oranges[]" VALUE=2>
<INPUT TYPE="text" NAME="oranges[]" VALUE=3>

When you submit the form, you can loop through your oranges to get each value.

However, this mucks up your javascript if you are accessing the value of each orange text box, because when you put [] beside the NAME, javascript no longer recognizes those oranges as an array.

In perl, those oranges without the []would still be received as an array (12), which you can then break apart and access element by element. Is this possible in PHP?



 About Notes


Previous page
 virtual
 Updated
Sun, 06 Aug 2000
array 
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.