0

I have this following class:

    Class myclass{
     public static $item_row_name = array(
            array('Item 1','Item_1','Help Label 1','#Item1'),
            array('Item 2','Item_2','Help Label 1','#Item2'),
            array('Item 3','Item_3','Help Label 1','#Item3'),
            array('Item 4','Item_4','Help Label 1','#Item4')
     );

   public static function pr_row($tableau){ 

                $var ='';

          foreach ($tableau as $row) {
            echo $count; 
            $label=$row[0];
            $name=$row[1];
            $help=$row[2];
            $balisecss=$row[3];
            $var.=$label;
            $var.=$name;
            $var.=$help;
            $var.=$balisecss;
return $var;
}
}
}  

In an another file i have this code :

    $testtab3 = myclass::$item_row_name;
$display=myclass::pr_row($testtab3);
echo $display;

This loop only returns the first array

How can i declare correctly my array? Maybe with serialize...? Thanks

1 Answer 1

3

Because that's what you ask for. $row is array('Item 1','Item_1','Help Label 1','#Item1'), $rowitem is 'Item 1' and $rowitem[0] is the first character.

You probably want

foreach(myclass::$item_row_name as $row) {
    echo $row[0];
}

or

foreach(myclass::$item_row_name as $row) {
    foreach($row as $rowitem) echo $rowitem;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Ok but in another function i have this ...: public static function pr_item_row($tab){ foreach ($tab as $row) {.... And in an another file i have : myclass::pr_item_row($item_row_name); It return only the first array...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.