Search code examples
phparrayspushexplodearray-push

Add Some Value to index-0 in Array before explode function in PHP


I have a code similar to

$results = array();
array_push($results, $term);
//after a few more lines
$results=explode(",", $resutl_string[1]);

but necessarily overwrite index 0 and I am unable to save $term on index 0, although I can successfully push $term at the end,

wondering for some clue or help to put my $term at index 0

thanks in advance


Solution

  • If you're looking for the array to be the term plus the current contents, you can use this:

    array_unshift($term, $results);