PHP Array Functions In Hindi

📔 : PHP 🔗

PHP हमें कई सारे array functions provide कराती है जिनकी help से हम Array create , update , array merge और बहुत से Operations perform कर सकते हैं।  कुछ array functions इस प्रकार हैं -


Function NameUses
array()pass की गयी values का Array create करता है।
count()
यह Array में मौजूद element की संख्या बताता है।
is_array()is_array() method check करता है , कि कोई variable Array है या नहीं।
array_push()array_push() method का use एक या एक से अधिक values को Array में append (Add) करने के लिए किया जाता है।
array_pop() array_pop() function , Array में से last element remove है।
array_shift()array_shift() function , Array में से first element remove करता है।
array_unshift()
array_unshift() method का use एक या एक से अधिक values को Array में prepend (Add) करने के लिए किया जाता है।
array_slice()दिए गए Array में से offset के according new Array return करता है।
array_keys()
यह associative array में से keys का Array return करता है।
in_array()
in_array() check करता है कि value Array में exist करती है या नहीं।
array_sum()array_sum() , Array के integer elements का sum return करता है।
array_product()
यह numeric Array values का multiplication / product return करता है।
array_values()
यह associative array में से values का indexed Array return करता है।
array_combine()array_combine() method , दो Indexed Array Elements को आपस में key => value pair में Associate करके एक नया Associative Array बनाता है।
array_diff()array_diff() method , दो या दो से अधिक Arrays का difference return करता है।
array_merge()array_merge() , एक या एक से अधिक Array के elements को आपस में merge करता है।
array_search()array_search() का use किसी Array में value को search करने के लिए किया जाता है।.
array_map()Tarray_map() function Array के प्रत्येक value को user defined callback function में send करता है , और एक Array नई values के साथ return करता है।
array_reverse()
returns an array with element in reverse order.
explode()
explode() function का use String से Array में convert करने के लिए किया जाता है।

PHP is_array

is_array() function check करता है कि दिया गया variable का type ARRAY है या नहीं।

File : array_fun.php

CopyFullscreenClose Fullscreen
<?php
    $arr = ['Girish', 'Mohit', 'Rahul'];
    if(is_array($arr))
        echo '$arr is an array';
    else
        echo '$arr is not an array';
?>
Output
$arr is an array 

PHP array_push

यह new element को array में सबसे last में insert करता है।

File : array_fun.php

Copy Fullscreen Close Fullscreen
<?php
    $arr = ['Girish', 'Mohit', 'Rahul'];
    array_push($arr, 'Rohit');
    echo"after inserting new item";
    echo "<pre>";
    print_r($arr);
?>
Output
after inserting new item
Array
(
[0] => Girish
[1] => Mohit
[2] => Rahul
[3] => Rohit
)

PHP array_pop

यह array में से सबसे last element को remove करता है।

File : array_fun.php

CopyFullscreenClose Fullscreen
<?php
    $arr = ['Girish', 'Mohit', 'Rahul'];
    array_pop($arr);
    echo"after removing the last item";
    echo "<pre>";
    print_r($arr);
?>
Output
after removing the last item
Array
(
[0] => Girish
[1] => Mohit
)

PHP array_shift

यह function array में से सबसे पहले element को remove करता है।

File : array_fun.php

CopyFullscreenClose Fullscreen
<?php
    $arr = ['Girish', 'Mohit', 'Rahul'];
    array_shift($arr);
    echo"removes first value from the array";
    echo "<pre>";
    print_r($arr);
?>
Output
removes first value from the array
Array
(
[0] => Mohit
[1] => Rahul
)

PHP array_unshift

यह array में सबसे पहले index पर new element को insert करता है।

File : array_fun.php

CopyFullscreenClose Fullscreen
<?php
    $arr = ['Mohit', 'Rahul'];
    array_unshift($arr, 'Girish');
    echo"insert new value at the beginning of the array";
    echo "<pre>";
    print_r($arr);
?>
Output
insert new value at the beginning of the array
Array
(
[0] => Girish
[1] => Mohit
[2] => Rahul
)

PHP array_sum And array_product

array_sum() function array में मौजूद सभी numeric values का Addition return करता है। जबकि array_product() array में मौजूद सभी numeric values का Product return करता है।

File : array_fun.php

CopyFullscreenClose Fullscreen
<?php
   $arr = [10, 20, 30];
   echo "Sum of array elements : ". array_sum($arr);
   echo "<br>Product of array elements : ". array_product($arr);
?>
Output
Sum of array elements : 60
Product of array elements : 6000

? अगर array में numeric value के साथ mixed type value भी होती है तो PHP array_sum() / array_product() function run कराते समय उन्हें 0 मानती है।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers