My Life with PHP

Example:

<?PHP $ arr=array?(10,20,=30); print-r($orr); ?> save:array 4.php output:array([o]=30[1])

Example:

<?PHP
$ arr=arroy();                                       
$ arr[0=10];                                         
$ arr[1=20];
print-r($ arr);
?>
saveas:array 5.php
output:array([o]=10[1])

Example:

we can provide string as array elamentkeythis concept is called as assoctive array.

<?PHP $ arr=array(); $ arr['long'='php' $ arr['manager']='scott' print-($ arr); ?> save as:associativerray 5.php Output:array([longe]=php[manger]= shoft)

count():

this f? returns total no. of arroy elements.
 <?php                                
   $ arr =array(10,20,30);                            
   echo count($ arr);
   ?>
save:array count .php
   Output:3
   

sort() this f? arranges the array elaments in ascending order with new key.

Example:

 <?php
      $ arr=array(10,5,20,30);
      sort($ arr);                                
      print-($ arr);                               
?>  

Example:

                                              
<?php                                  
$ arr=array(10,'a'=5,20,30);                        
sort($arr);                                         
print-r($arr);                                      
?>                                         
saveas:arraysoft.php 
Output:array
(
    [o]=5
    [1]=10
    [2]=20
    [3]=30
    )
    =>  same output as above

Pageno: 13

rsort:

Arrages array of elements Descending(Array). Order with New Keys.



Expaple:

Array[0]=>30 [1]=>20 [2]=>10 [3]=>5

program:

<?php
$arr=array(10,5,20,30);
rsort($arr);
Print_r($arr);
?>

Asort:

Asendin Order with Original Keys.

< ?php
$arr=array(10,'a'=>5,20,5=>30;)
asort=($arr);
print_r($arr);
?>

Otp:

a=>
0=>10
1=>20
2=>30.

asort:

Desending Order with Original Keys.

Ksort:

Dsending Order based on Array Keys.

<?php 
$arr=array(10,100=>5,20,5=>30);
ksort=($arr);
print_r($arr)
?>

Krsort

Dersending based on array Keys.

array_sum:

To get the sum array Elements.

Example 1:

<?php
$arr=array(10,20,30);
echo array_sum($arr);
?>

Example 2:

<?php
$arr=array(10,20,30,'scott');
echo array_sum($arr);
?>

array_product:

Get Product Of Element.

Example 1:

<?php
$arr=array(10,20,30); echo array_product($arr)
?>

page no:14

array-push:

By using this function, we can add new element of end pt.of Array & it returns total no.of array elements.

      
     

Example:1

<?php
                                                               out put:14 $arr=array(10,20,30);
echo array_push($arr,40);
?>

Example:2

<?php
$arr=array(10,20,30);
echo array_push($arr)
print_r($arr);
?>

array-pop:

Deletes the last element of Array and returns the value of the element.

           
         

Example:1

<?php
                                                               out put:30 $arr=array(10,20,30);
echo array_pop($arr);
?>

Example:2

<?php
$arr=array(10,20,30);
echo array_pop($arr)
print_r($arr);
?>

array-shift:

This function removes the 1st element of on Array & Returns the value of that element.

       
     

Example:1

<?php
$arr=array(10,20,30);
echo array_shift($arr);
print_r($arr);
?>

sarray-unshift:

By using this function we can add on element of the bogining of Array & Returns the total no.of Array Element.

EXAMPLE

             
                        <?php
                        $arr=array(10,20,30);
                        echo array_unshift($arr,5);
                        print_r($arr);
                        ?>

array-combine

this function creates a new array by combining the elements of 2 arrays. new array is keys are value of '1'st array new array values are values of '2'nd array

EXAMPLE


                        <?php
                        $arr1=array(10,20,30);
                        $arr2=array(a,b,c);
                        $narr=array_combine($arr1,$arr2);
                        print_r($narr);
                        ?>

array-diff

this function compares the value of 2 array elements &returns the array of 1 st element

EXAMPLE


                         <?php
                         $ arr1=array(10,20,30);
                         $arr2=array(10,30,40);
                         print_r(array_diff($arr1.$arr20));
                         ?>

array-diff-assoc

it compares keys and values of 2 array & returns the difference from '1'st array

EXAMPLE


                       <? php
                       $arr1=array(10,20,30);
                       $arr2=array(10,30,40);
                       print_r(array_diff_assoc($arr1.$arr2));
                       ?>

array-diff-key

it compares 2 array keys & returns the difference from '1'array

EXAMPLE


                       <?php
                        $arr1=array(10,20,30);
                        $arr2=array(10,2=>30,40);
                        $narr=array_combine($arr1,$arr2);
                        print_r(array-diff-key($arr1.$arr2));
                        ?>