PHP array in Hindi

PHP array introduction

Array एक data structure है जो data को key value formate में store करता हैi. array matalab php में ऐसा variable जिसमे हम multiple values को store कर के रख सकते है|. php के simple variable में क्या होता है की हम at the time एक टाइप की ही value को store कर सकते हैi. अगर एक से ज्यादा value को store करना पद जाये तब हम array variable में multiple value store करके अपने program logic में इस्तेमाल कर सकते है|.

Array और array variable को कैसे create सकते है|

php में array को create करने के लिए array() function का इस्तेमाल किया जाता हैi.

array();

php में array variable को define करने के लिए dollar ($) sign का इस्तेमाल किया जाता है|.

$arr = array();

ऊपर के example में देख सकते है की हमने array() function से जो array create किया है उसे हमने $arr नाम के variable में asign कर दिया हैi. मतलब की array variable को ऊपर की example की तरह define या create किया जाता हैi.

What is an array?

Array similar data types के data और items का collection है. php programing में array का इस्तेमाल करना एक good practice है जब multiple value एक single variable में store हो तो.

For example जब हम similar data types के value को 5 variable में store करते है तो हम कुछ इस तरह से लिखेंगे|

 <?php
  $variable1 = 5;
  $variable2 = 10;
  $variable3 = 15;
  $variable4 = 20;
  $variable5 = 25;
?>

मान लीजिये अगर 100 या 1000 similar type ki value है तो उस values के लिए variable क्रिएट करना और उसको मैनेज करना बहुत कठिन हो जाता है|. इसके लिए हम php array का इस्तेमाल करके इस सभी multiple values को एक single variable में store करा के php codding में आसानी से manage कर सकते है|

Types of array

php में तीन type के array है जो multiple values को store कर सकते हैi.

  1. Indexed array
  2. Associative array
  3. Multi-dimensional array

1.Indexed array

php indexed array में data और item जो store होंगे वह सभी एक specific position पे store होंगे उसे हम indexs कह सकते है indexed array में data और itme store होंगे उसकी index key numeric (number) के formate होती है इस लिए हम उसको numeric array बी कह सकते है और उसकी default index key value zero ( 0 ) होती हैi.

syntax:

array( element1, element2, element3,... )

Example:

<?php
  $langs = array("html","css","jquery","php","wordpress","laravel");
  echo "<pre>"; print_r( $langs );  echo "</pre>"; 
?>

output:

Array(
      [0] => html
      [1] => css
      [2] => jquery
      [3] => php
      [4] => wordpress
      [5] => laravel
)

2.Associative array

php associative array में data और item store होंगे उस सभी data और item को एक index key में assign किया जायेगा और associative array में वह key string type में होगी और user उसे manually defined करता हैi. इस लिए उसे associative array कहते हैi.

syntax:

array( element1, element2, element3,... )

Example:

<?php
  $langs = array( 
      "one"=>"html",
      "two"=>"css",
      "three"=>"jquery",
      "four"=>"php",
      "five"=>"wordpress",
      "six"=>"laravel"
  ); 
  echo "<pre>"; print_r( $langs );  echo "</pre>"; 
?>

output:

Array(
       [one] => html
       [two] => css
       [three] => jquery
       [four] => php
       [five] => wordpress
       [six] => laravel
)

3.Multi-dimensional array

Multi-dimensional array एक php array है. जिसमे element और item बी एक array के formate हो सकते हैi. Multi-dimensional array में एक variable बी array को store करता हैi.

syntax:

array(
		array( elements... ),
		array( elements... ),
		......
	)

Example:

<?php
 $arr = array(
         array("Html","css","jquery"),
         array("php","laravel","wordpress",
                'all'=>array('Html', 'css', 'jquery', 'php', 'laravel', 'wordpres' ),
              ),
            );
echo "<pre>";    print_r( $arr ); echo "</pre>";
?>

output:

Array
(
    [0] => Array
        (
            [0] => Html
            [1] => css
            [2] => jquery
        )

    [1] => Array
        (
            [0] => php
            [1] => laravel
            [2] => wordpress
            [all] => Array
                (
                    [0] => Html
                    [1] => css
                    [2] => jquery
                    [3] => php
                    [4] => laravel
                    [5] => wordpres
                )

        )

)

1 thought on “PHP array in Hindi<span class="post-views-after-title"><span class="post-views-after-title"><div class="post-views content-post post- entry-meta"><span class="post-views-icon dashicons dashicons-visibility"></span><span class="post-views-label">Post Views : </span><span class="post-views-count">424</span></div></span></span>”

  1. Pingback: php array() function lists in hindi - RjtechyG

Leave a Comment

Your email address will not be published. Required fields are marked *