how can sort an array in php

how can sort an array in php



<?php
$myworld = array("a"=>"php","b"=>"learning","c"=>"i'm");
asort($myworld);
print_r($myworld);
?>

Out put will be
Array
(
[c] => i'm
[b] => learning
[a] => php
)

reverse sort an array

reverse sort an array



<?php
$myworld = array("a"=>"everything","b"=>"nothing","c"=>"is");
arsort($myworld);
print_r($myworld);
?>

Which prints this:

Array
(
[b] => nothing
[c] => is
[a] => everything
)

how can reset array values

how can reset array values
<?php
$numbers = array("one","two","three");
next($number);
$thisvalue = current($number); echo "We are now at $thisvalue\n\n";
$first = reset($number);
echo "Back to $first";
?>

array loop in php

array loop in php


<?php
$alphabet 
range("A","Z");
foreach(
$alphabet as $letter) { echo "Ooh look!  The letter $letter\n"; } ?> 

how can output data disply in array

how can output data disply in array


<?php
$value 
= array("one","two","three","four"); print_r($values); ?> 


Outputs:

Array
(
[0] => one
[1] => two
[2] => three
[3] => four
)

two dimensional array in php example

two dimensional array in php example


<?php
$myarray 
= array(); $myarray[0] = array(1,2,3,4); $myarray[1] = array(5,6,7,8); // foreach($myarray as $v) {
foreach(
$v as $myv) {
echo 
"$myv<br>";
}
//prints 1 through 8 on screen ?> 

how can check value exit in array

how can check value exit in array


<?php
$value = array("one","two","three","four");
$new_value = "five";
if (in_array($newvalue,$values)) { echo "$newvalue is already in the array!"; }
?>

main difference between session and cookies in php

main difference between session and cookies in php



main difference between  cookies and session,cookies are stored in the user's browser, and sessions are not. Sessions store in server maches,This difference determines what each is best used for.Cookies can keep information in the user's browser until deleted. If a person has a login and password, this can be set as a cookie in their browser so they do not have to re-login to your website every time they visit. You can store almost anything in a browser cookie. The trouble is that a user can block cookies or delete them at any time. If, for example, your website's shopping cart utilized cookies, and a person had their browser set to block them, then they could not shop at your website.