2016-05-05 14 views
0

Ich habe eine Zeichenfolge.Erstellen eines PHP-Arrays aus einer explodierten Zeichenfolge

$string = "this is my string"; 

Also ich möchte es explodieren.

$explode = explode(' ', $string); 

Jetzt möchte ich wissen, ob es möglich ist, jedes Wort in ein Array einzufügen, damit ich das bekommen kann.

$array = array('this', 'is', 'my', 'string'); 
+5

Die '$ explode' ist das Array ähnlich wie $ array. Die 'explode'-Funktion hat es bereits getan. –

+5

Genau das hast du in '$ explode', was ist das Problem ?! – Rizier123

+1

Mit 'explode()' hast du * schon * ein gewünschtes Array ('$ array' =' $ explode') – fusion3k

Antwort

0

Genau wie Frayne Konok gesagt, die $explode ist die Anordnung ähnlich wie $array. Die Explosionsfunktion hat es bereits getan.

0
$array = array(); 
$string = "this is my string"; 
$explode = explode(' ', $string); 

for ($i=0; $i<count($explode); $i++) { 
    array_push($array, $explode[$i]); 
} 
print_r ($array); 
Verwandte Themen