Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php

What is the join method in PHP?

Sarvech Qadir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

The join() method returns an entire array as a string. The method separates elements with a specified separator; the default separator is a comma (,).

The join method in PHP is used to concatenate an array to return a string. The interesting thing is that the array can be concatenated using a separator. It can be a space (" "), a hyphen (-), a character, etc.

Syntax

join(separator,array)

Parameters

  1. separator: An optional parameter – it refers to the separator used to concatenate a given array.
  2. array: a required parameter – it refers to the array that needs to be converted to a string.
<?php
$arr1 = array('Welcome','to','Educative!');
// array concatenated using a space
$var = join(" ",$arr1);
echo $var."\n";
// array concatenated using a hyphen
$var = join("-",$arr1);
echo $var."\n";
// array concatenated using no separator
$var = join($arr1);
echo $var."\n";
?>

RELATED TAGS

php

CONTRIBUTOR

Sarvech Qadir
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring