Hi Guest

MobileUser

1 HomePage 1 Jobs 1 WalkIn 1Articles  

Cat Exam

 :) Latest Topic
AJAX
VB.NET
SQL Query
UDDI
CLASS
JavaScript Questions
SharePoint Interview
SilverLight
WCF
general knowledge
 ASP.NET
 :) Hot Jobs
 
 :) Latest Articles


  

 


something about array creation sorting searching in php
Question Posted on 13 Jul 2011

Home >> PHP >> Example >> something about array creation sorting searching in php




here is the syntax for array creation,search ,loop from the array in php

******syntax to create and array in Php******
< ?php
$myarray = array(1,2,3,4,5,6,7,8,9,10);
  or
$myarray = range(1,10);
  or
$myarray = range(a,z);
? >


******syntax to view item of array******
< ?php
$values = array("a","b","c","d");
print_r($values);
? >


******syntax of loop foreach to print a to z******
< ?php
$alphabet = range("A","Z");
foreach($alphabet as $letter) { echo "The letter $letter\n"; }
? >


*******syntax to search item in array*******
< ?php
$values = array("a","b","c","d");
$newvalue = "cr";
if (in_array($newvalue,$values)) { echo "$value is already in the array!"; }
? >


******syntax for shuffle or random item from a to z******
< ?php
$values = range("A","Z");
shuffle($values);
print_r($values);
? >


******syntax for sorting in array******
< ?php
$myworld= range("A","Z","O","P","L","k");
arsort($myworld);
print_r($myworld);
? >


******syntax for multi-dimensional array******
< ?php
$multiarray = array(array(5,4,3,2,1),array(7,8,2,9,10));
array_multisort($multiarray[0],SORT_ASC);
print_r($multiarray);
? >


******syntax for get count of element in array ******
< ?php
$values = array(1,2,3,4,5,6,7,8);
$elements = array_unshift($values,1);
echo "No of elements: $elements \n\n";
print_r($values);
? >


******syntax for number of times a vallue appears in array ******
< ?php
$values = array(a,b,c,d,s,a,a,c,d,f,a,s,a,a,b,d,d,d);
$most_popular = array_count_values($values);
print_r($most_popular);
? >


******syntax to find size of an array *******
< ?php
$values = range("A","Z");
echo count($values);
? >


******syntax to find randome number from array ******
< ?php
$number = range(1,100);
$rannumber = array_rand($number);
echo "Number is: $rannumber\n\n";
? >


******syntax to remove first value from array ******
< ?php
$values = array(a,b,c,d,e,f,g);
$first = array_shift($values);
echo "First value is: $first";
print_r($values);
? >

******syntax to invert array ******
< ?php
$values = array("b","a","c");
print_r($values);
$values = array_flip($values);
print_r($values);
? >
0
0



 
 Input Your Comments Or suggestions(If Any)
 Name
 Email(optional)
 Comments


Other Important Questions
something about array creation sorting searching in php
Remove whitespace from end of string in PHP
difference between htmlentities() and htmlspecialchars()
How to gernate random value in PHP
Number of time a value occur in array in PHP






 
Top Searches:asp net questions vb net questions sql query uddl questions class javascript Questions sharepoint interview questions and concept silverlight questions and concept wcf questions beans general knowledge ajax questions
PHP | Biztalk | Testing | SAP | HR |