Question

I'm trying to implode variables, but it's not working correctly:

$models = array("$model0, $model1");

$modelfinal = implode("," , $models);

$modelfinal only returns , ,

I'm guessing I'm way off...anybody?

Was it helpful?

Solution

The following statement creates an array with exactly one string in it, which is comprised of the values of two (apparently) undefined variables separated with a comma:

$models = array("$model0, $model1");

The end result is the same as if you had done this:

$models = array(", ");

Now you're imploding it using a comma as the separator, which doesn't do anything since there's only one element in the array (a string with a comma and a space).

Assuming $model0 and $model1 are defined (which is a problem you'll need to look into first), you can get your desired result either by:

  • directly using $modelfinal = "$model0, $model1",
  • or by using $models = array($model0, $model1); followed by the implode.

OTHER TIPS

here is your problem "$model0, $model1" change it to this code

$models = array($model0,$model1);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top