SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot virginiamonkeys's Avatar
    Join Date
    Jun 2003
    Location
    Stafford, Virginia, USA
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multidimension Array Search Problem

    I have this code trying to search each layer for a specific string:

    PHP Code:
    $found = array();

    if(
    is_array($newlist)){
        foreach (
    $newlist as $key => $value){
                echo 
    $key.'<br />';
            if(
    is_array($newlist[$key])){
            foreach (
    $newlist[$key] as $key => $value){
                echo 
    '&nbsp;&nbsp;'.$value.'<br />';
                
    $found[$key] = array_search('o'$value);
                echo 
    '&nbsp;&nbsp;'.$found[$key].'<br />';
                }
            }
        }

    I put in the echo $key and $value to see if it's opening each layer, which it is. But it's printing off blanks at the echo $found[$key]. I've tried a few different variations. I put in the letter o as a search term just to see if it's working.

  2. #2
    SitePoint Zealot virginiamonkeys's Avatar
    Join Date
    Jun 2003
    Location
    Stafford, Virginia, USA
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Trying something slightly different, but I keep getting a blank screen:

    PHP Code:
    if(is_array($newlist)){
        foreach (
    $newlist as $key => $value){
                echo 
    $key.'<br />';
            if(
    is_array($newlist[$key])){
            foreach (
    $newlist[$key] as $key => $value){
                echo 
    '&nbsp;&nbsp;'.$value.'<br />';
                if (
    array_search('o'$value) = true){
                echo 
    '&nbsp;&nbsp;TRUE<br />';
                    } else {
                echo 
    '&nbsp;&nbsp;FALSE<br />';
                    }    
                }
            }
        }

    The blank screen stops if I comment out the following. if (array_search('o', $value) = true){

  3. #3
    SitePoint Zealot virginiamonkeys's Avatar
    Join Date
    Jun 2003
    Location
    Stafford, Virginia, USA
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I put the double == and it at least doesn't blank screen on me, but everything returns FALSE:

    PHP Code:
    if(is_array($newlist)){
        foreach (
    $newlist as $key => $value){
                echo 
    $key.'<br />';
            if(
    is_array($newlist[$key])){
            foreach (
    $newlist[$key] as $key => $value){
                echo 
    '&nbsp;&nbsp;'.$value.'<br />';
                if (
    array_search('o'$value) == true){
                echo 
    '&nbsp;&nbsp;TRUE<br />';
                    } else {
                echo 
    '&nbsp;&nbsp;FALSE<br />';
                    }    
                }
            }
        }


  4. #4
    SitePoint Zealot virginiamonkeys's Avatar
    Join Date
    Jun 2003
    Location
    Stafford, Virginia, USA
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried "in_array" and it still flags everything as false:

    PHP Code:
    if(is_array($newlist)){
        foreach (
    $newlist as $key => $value){
                echo 
    $key.'<br />';
            if(
    is_array($newlist[$key])){
            foreach (
    $newlist[$key] as $key => $value){
                echo 
    '&nbsp;&nbsp;'.$value.'<br />';
                if (
    in_array("o",$value)){
                echo 
    '&nbsp;&nbsp;TRUE<br />';
                    } else {
                echo 
    '&nbsp;&nbsp;FALSE<br />';
                    }    
                }
            }
        }


  5. #5
    SitePoint Zealot virginiamonkeys's Avatar
    Join Date
    Jun 2003
    Location
    Stafford, Virginia, USA
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured this one out. I was using the wrong function. I needed strstr():

    PHP Code:

    if(is_array($newlist)){
        foreach (
    $newlist as $key => $value){
                echo 
    $key.'<br />';
            if(
    is_array($newlist[$key])){
            foreach (
    $newlist[$key] as $key => $value){
                echo 
    '&nbsp;&nbsp;'.$value.'<br />';
                if (
    strstr($value,"o")){
                echo 
    '&nbsp;&nbsp;TRUE<br />';
                    } else {
                echo 
    '&nbsp;&nbsp;FALSE<br />';
                    }    
                }
            }
        }



Bookmarks

Posting Permissions

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