If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
PHP में Array एक ordered map है। और map एक type है जो value को key के साथ associate करता है means key value pair में data store करता है।
PHP में Array दो तरह से define कर सकते हैं।
और दोनों में ही हम comma ( , ) separated values pass करते हैं।
$arr1 = array('Rahul', 'Raju', 'Shyam'); $arr2 = ['Ram', 'Lakhan'];
array define करने के लिए हम दोनों में से कोई भी method use कर सकते हैं।
File : array.php
<?php
$arr1 = array('Rahul', 'Raju', 'Shyam');
echo "<pre>";
print_r($arr1);
?>
Array ( [0] => Rahul [1] => Raju [2] => Shyam )
जहां print_r() एक predefined PHP function है जिसका use array variables में stored data को display करने के लिए किया जाता है। PHP Array display करने का यह सबसे अच्छा method है।
example में आप देख सकते हैं कि जो values हमने जिस order में store की थी उसी order में values automatically एक key के साथ associate हो गई है।
Note - PHP में array define करने के लिए हमें array का type define करने की जरूरत नहीं होती है। जैसे कि JAVA या C में हमें array define करते समय array का type define करने की जरूरत पड़ती है और वह array define किये गए type की value को accept करता है।
यही reason है कि PHP में array किसी भी तरह की value (string , integer , float , boolean etc. ) को store कर सकते हैं।
See Example :
File : array2.php
<?php
$arr1 = array('Rahul', 10, 56.56, true);
echo "<pre>";
print_r($arr1);
?>
Array ( [0] => Rahul [1] => 10 [2] => 56.56 [3] => 1 )
तो देखा आपने कि किस तरह से PHP Array में हम किसी भी तरह की values store करा सकते हैं।
PHP में दो type के array होते हैं।
अभी ऊपर जो हमें Examples देखें हैं वो Indexed Array है।
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