0

I got the values like following and need to store in single variable like $value = "Corporis dolore nemo","Cupidatat atque enim","Rerum consequatur I"

Array
(
    [0] => Corporis dolore nemo
    [1] => Cupidatat atque enim
    [2] => Rerum consequatur I
)

I tried using following code but it give array to string conversion error.

    foreach($value['title'] as $val)
           {
               $me[] = $val  ;
           }
$model->title = $me;
samita
  • 165
  • 1
  • 11
  • Check this [enter link description here](https://stackoverflow.com/questions/7490488/array-to-string-php) out. – funbrain9 May 13 '20 at 03:42
  • Check this [enter link description here](https://stackoverflow.com/questions/7490488/array-to-string-php) out. – funbrain9 May 13 '20 at 03:44

2 Answers2

0

I think what you're looking for is implode

$model->title = implode(", ", $value['title']);

This makes it so you don't need the foreach

Jason Groulx
  • 400
  • 2
  • 10
0
<?php
    $arr = array('Test1','Test2','Test3','Test4');
    echo implode(", ",$arr);
?>

The implode() function returns a string from an array.

The explode() function splits a string into an array.

Check this out also.

funbrain9
  • 503
  • 6
  • 15