2

I need to remove keys from my arrays, and array be like

Array ( [0] => 23/2 [1] => KG Halli [2] => D' Souza Layout [3] => Sampangi Rama Nagar [4] => Bengaluru [5] => Bangalore Urban [6] => Karnataka [7] => India [8] => 560001 )

and i need it as

23/2, KG Halli, D' Souza Layout, Sampangi Rama Nagar, Bengaluru, Banglore Urban

3
  • 3
    Use the implode() function. ex: implode(', ', $your_arr); Commented Jul 6, 2017 at 6:19
  • 2
    Do you want to print or echo the values? Or you want to use it in another function? Commented Jul 6, 2017 at 6:20
  • I just need print it. Commented Jul 7, 2017 at 8:55

6 Answers 6

2

php implode() function is the answer to your question

You can use implode to make your array values as a string and attach each value with any separator i.e. ',' or a space.

implode(', ', ARRAY);
Sign up to request clarification or add additional context in comments.

Comments

1
$required_str = implode(',',$array);

Comments

1

Try this:

$yourString = implode(", ", $yourArray);

Comments

1

use string function implode()

$arr = array('23/2','KG Halli',"D' Souza Layout",'Sampangi Rama Nagar' ,'Bengaluru','Bangalore Urban','Karnataka', 'India',560001);
echo implode(",",$arr);

Comments

1

You can use implode() php function to make an array to string

Just like this

$array=['id'=>12,'no'=>1234]
$String = implode(", ", $array);//it give o/p as "12,1234"

Or if you want array with no key value then you can use array_values() Just like this

$array=array_values($array);//it give o/p as [12,1234]

Comments

0

Simply use the implode() function of PHP.

Example: implode(', ', $your_arr);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.