PHP implode()

📔 : PHP 🔗

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

PHP implode() Syntax

implode ( string $separator , array $array );

implode() function दो arguments accept करता है।

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

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


PHP implode() Example

File : php_implode.php

CopyFullscreenClose Fullscreen
<?php
  /*string separated by comma */
  echo implode(",", $array);
  
  echo "<br>";
  
  /*string separated by under score */
  echo implode("_", $array);
?>
Output
lastname,email,phone
lastname_email_phone

? Example में <br> का use सिर्फ line break करने के लिए किया गया है।

Possible Cases

  1. Empty Array को implode करने पर आपको empty String ही return होगी।

  2. Boolean Value true / True के लिए 1 return होगा।

    echo implode(",", [true, True]);
    /*Output*/
    1,1
    
  3. Boolean Value false / False के लिए empty String return होगी ।

    echo implode(",", [false, False]);
    /*Output*/
    Nothing*
    

PHP explode()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