-2
$dizi=array();
$a=2;
$dizi[]= $a;
$dizi[]= 4;
$dizi[]= 7;

Array ( [0] => 2 [1] => 4 [2] => 7 )

how can i assing to variable like :

$variable=247
dogacan7
  • 7
  • 3

4 Answers4

1

You can implode an array on a delimiter. If you provide no delimiter, it concatenates all the values together.

$variable = implode('',$dizi);

Outputs: $variable = 247;
Ohgodwhy
  • 49,779
  • 11
  • 80
  • 110
0

make a variable and set it equal to `implode("", $array); now if you echo the variable the result will be values of array without space or line-break.

$dizi=array();
$a=2;
$dizi[]= $a;
$dizi[]= 4;
$dizi[]= 7;

$variable = implode("", $dizi);
echo $variable;
saqib kifayat
  • 136
  • 2
  • 14
0

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

$variable = implode("", $dizi);

Output

$variable=247

You can also try the join function.

The join() function returns a string from the elements of an array.

$variable = join("", $dizi);

Output

$variable=247

The join() function is an alias of the implode() function.

Murad Hasan
  • 9,565
  • 2
  • 21
  • 42
0

Though implode is the best way, i have tried using json_encode

$variable=str_replace(array('[', ']',','), '', json_encode($dizi));

Outputs: $variable = 247;

Shashank Shah
  • 2,077
  • 4
  • 22
  • 46