Hi Guest

HomePage

1 1

To improves our performance please Like Share Subscribe(Will boost us)

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




Most Visited Questions:-

Deep Learning Questions Answers
Below are the different Deep Leaning Questions and answer a More...

What is Gulpjs and some multiple choice questions on Gulp
Gulpjs is an open source whihc helps in building Javascript More...

Continuous Integration Questions Answers
Below are the 20 odd questions for CI or Continuous Integra More...

Derived relationships in Association Rule Mining are represented in the form of __________.
Derived relationships in Association Rule Mining are repres More...

Microservices Architecture Questions Answers
Below are the different questions on Microservices Architec More...




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






Most Visited Questions
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 |
     
 
Privacy policy | Terms and Conditions | Blog


If the copyright of any questions or content or syntax belong to you email us we will remove that(info@crackyourinterview.com or crackyourinterview2018@gmail.com)
 

1
Home About Us GroupChat
 
Sitemap Feedback Contact us