Search Marketing

   
   

Finding the Position of an Element in an Array

Fri May 02, 2008 10:03 pm
<<     >>
Comments: 0 Views: 269

Finding the position of an element in an array such as:

a,b,c,d,e,f

What is the position of the letter d?

$x = array();
$x[] .= "a";
$x[] .= "b";
$x[] .= "c";
$x[] .= "d";
$x[] .= "e";

print_r ($x);

Array ( [0] => a [1] => b [2] => c [3] => d [4] => e )


$position = array_search("d",$x);

echo $position;

3

The position of the letter "d" in the array is 3 because arrays begin at zero.



Comments
Name:
*
URL: http: (ex. cnn.com)
Comment:
*
Number:
Math (29 + 4)
* required
SubCategories
Regular Expressions

© 2019 Christonium LLC

Christonium.com
|
Terms of Use
|
Privacy
ccc