PHP explode()

📔 : PHP 🔗

PHP explode() function का use String से Array में convert करने के लिए किया जाता है।

PHP explode Syntax

explode ( string $separator , string $string , int $limit = PHP_INT_MAX);

यह method तीन arguments accept करता है।

  1. string $separator | required : separator वह string है , जिसके according आप String को explode करना चाहते हो। ये whitespace , comma (,) , या underscore (_) कुछ भी हो सकता है।

  2. string $string | required : वो string जिसे आप Array में convert करना चाहते हैं।

  3. int $limit = PHP_INT_MAX | optional : यह optional होता है , basically इसमें pass किये गए number तक ही String , Array में convert होती है।

    Possible values
    • 0 pass करने String 1 index तक ही explode होगी means सिर्फ 1 element return होगा।

    • Less Than 0 : negative value पर यह Array के last elements को छोड़कर Array return करता है।

    • Greater Than 0 : इस number तक ही String , Array में convert होती है।


PHP explode Example

File : php_explode.php

CopyFullscreenClose Fullscreen
<?php 
     $str = "Hello world. It's a beautiful day.";
    echo "<pre>";
    print_r (explode(" ",$str));
    echo "</pre>";
 ?>
Output
Array
(
    [0] => Hello
    [1] => world.
    [2] => It's
    [3] => a
    [4] => beautiful
    [5] => day.
)

Another Example

print_r (explode(" ",$str, -3));
/*Output*/
Array
(
    [0] => Hello
    [1] => world.
    [2] => It's
)

तो कुछ इस तरह से , PHP में explode() function work करता है। I Hope अब आपको explode() function के बारे में clear हो गए होंगे।

PHP implode()PHP in_array()

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