Results 1 to 4 of 4

Thread: Php Array Syntax Error

Hybrid View

  1. #1
    Join Date
    Apr 2012

    Smile Php Array Syntax Error


    I am fairly new to this and to forums .... so please can someone help me.

    I have this bit of code that is driving me insane. I cant begin to tell you how many times I have tried to go over it. What I am trying to do is retrieve the string of search critera from the DB, split it up and then make make the Checkboxes Checked if they were check for the search.

    The section of code is as follows and the error message I am getting is :
    Parse error: syntax error, unexpected T_FOREACH when I try run the code.
    Dreamweaver says that there is a syntax error on line 4.

    $myCriteria = substr($mySearch,0,-1);
    $XPcolors= explode("|",$myCriteria);*
    $seeds=array("SouthAfrica","Botswana","Namibia","Mauritius","Mozambique","Kenya","Tanzania","Uganda" ,"Zimbabwe","Zambia");

    foreach ($seeds as $supercolor) {
    if($supercolor == $XPcolors) {
    *echo "<option value=\"$supercolor\" SELECTED>$supercolor</option>";
    *} else
    **echo "<option value=\"$supercolor\">$supercolor</option>";


    Please Help !


  2. #2
    Join Date
    May 2004
    chennai, tamil nadu, India
    If you remove the *'s it works for me.
    Chris, Senior Developer,
    Php laravel developers,

  3. #3
    Join Date
    Apr 2012

    resolved Weirdest thing

    Thanks for the feedback .... and I had no idea what you were talking about because when I look at my code .... there are no stars .... but when I looked back at this post I noticed that there were these crazy little things popping up out of the blue. Craziest thing !! No wonder it was saying a syntax error.

    Thanks once again !!

  4. #4
    Join Date
    Jul 2009
    My house, sitting at the computer. Duh!
    Try this.

    PHP Code:
    foreach ($seeds as $supercolor)
    '<option value="'$supercolor'" SELECTED>'$supercolor'</option>';
    '<option value="'$supercolor'">'$supercolor'</option>';

    Previously the first conditional statement was checking to see if $supercolor == $XPcolors, and since $XPcolors was an array, that's the same as going if ($supercolor == array()). So by switching the condition to see if $supercolor is inside the $XPcolors array, you should be able to effectively compare values.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center