tags:

views:

72

answers:

3

How can I check if each value in the variable $c = 90,89,78,88; equal true I think you call it an array in my script one at a time?

This part checks the variable.

if($cat['id'] == $c){
    $url = $parent_url . $cat['url'];
    echo '<a href="' . $url . '" title="' . $cat['category'] . '">' . $cat['category'] . '</a>';            
}

Here is the PHP code.

$c = 90,89,78,88;

function make_list ($parent = 0, $parent_url = '') {
    global $link;
    global $c;

    foreach ($parent as $id => $cat) {

        if($cat['id'] == $c){
            $url = $parent_url . $cat['url'];
            echo '<a href="' . $url . '" title="' . $cat['category'] . '">' . $cat['category'] . '</a>';            
        }

        $url = $parent_url . $cat['url'];

        if (isset($link[$id])) {
            make_list($link[$id], $url); // $url adds url value to sub categories
        }               
    }       
}
A: 

your $c is not an array there - you need to make it an array e.g.

$arrayC = explode(',', $c);

check out the function on php.net/explode

then your if($cat['id'] == $c) would be better as if(in_array($cat['id'], $arrayC)

boobyWomack
I can't get this to work:(
FAQ
try and say more when you describe a problem - it helps others to know what isnt working or the error etc :) Good luck! please mod me up if you can, I havent any feedback here as I am new!
boobyWomack
+4  A: 
global $c; 

$cArray = explode(',',$c);

foreach ($parent as $id => $cat) { 

    if (in_array($cat['id'],$cArray)) {
Mark Baker
I can't get this to work:(
FAQ
also change the line before function to $c = '90,89,78,88';
Haim Evgi
@Haim Evgi As soon as I posted that I got it to work.
FAQ
A: 
$your_array = explode(",",$c);
foreach( $your_array as $value ) {
    if ( (int) $value === true ) {
         // here type what you what to do if true
    }
}
Gatman