-1

IM getting the error

Notice: Array to string conversion php

by calling my array from a outside class.. can anybody spot the problem here

script home.php

echo b::addarray(123, sea, 1);//i tried this way,dint work either("123","sea","1")
die();

the script with the array

class b
{

    static function addarray($a,$b,$c){

        $red = array();
        array_push($red, $a,$b,$c);
        return $red;
    }
}
Sho Gum Lew
  • 329
  • 1
  • 5
  • 17

3 Answers3

4

Try it as follows, as you were echoing an array you need to use print_r() or var_dump()

$re = new b();
$result = $re::addarray(123,'sea',1);
print_r($result);
Narendrasingh Sisodia
  • 21,247
  • 6
  • 47
  • 54
3

sea is a string ,it should be quoted.and try this

 <?php
        class b
    {

        static function addarray($a,$b,$c){

           static  $red = array();
            array_push($red, $a,$b,$c);
            return $red;
        }
        }


      print_r(b::addarray(123, "sea", 1));
    ?>
0
print_r(b::addarray(123, sea, 1));

  or

foreach(b::addarray(123, sea, 1) as $key=>$val) {

   echo $key."#".$val;

}
Subedi Kishor
  • 5,906
  • 5
  • 35
  • 53
selvan
  • 1,183
  • 3
  • 16
  • 24
  • foreach Parenthesis not closed foreach(b::addarray(123, sea, 1) as $key=>$val) {echo $key."#".$val; } –  May 28 '15 at 07:44