Jump to content

how to get the array contents and serialize data


new_member

Recommended Posts

Hi,

 

I want to know how to access the values of given array values using loop in php:

 

Array

(

[0] => Array

(

[test1] => testval

[test2] => testval2

)

 

i dont know what to loop and how to access it.

 

Moreover if i am serializing the given array using php serialize function it is giving me output as N;. I dont know whats the problem with the serialize function of my code as i use

 

serialize($this->['testing]);

 

[testing] => Array

(

[0] => Array

(

[test1] => test.com

[test2] => test2

[test4] => test4

 

)

 

)

 

Any help??

foreach

 

serialize() has a very specific set of purposes. You rarely ever need it. But on that note what you serialized was null, not an array, so there's something wrong there.

 

Blah blah blah post some code.

i know i have to use foreach but how to loop and access the content. I am unable to find this.

 

For serializing i am just using

 

serialize($this->['testing])

 

if i print $this->testing it gives me output

 

[testing] => Array ( [0] => Array ( [test1] => test.com [test2] => test2 [test4] => test4 ) )

 

but serializing it gives null dont know why

i know i have to use foreach but how to loop and access the content. I am unable to find this.

The page I linked to has a number of examples on how to use foreach.

 

For serializing i am just using

 

serialize($this->['testing])

No you're not because that's a syntax error.

 

if i print $this->testing it gives me output

 

[testing] => Array ( [0] => Array ( [test1] => test.com [test2] => test2 [test4] => test4 ) )

 

but serializing it gives null dont know why

Because you're trying to output two different things.

 

Try posting your complete code this time.

yes i have missed some quote while posting here.

 

serialize($this->test['testing'])

 

This is the complete code and array i have given above.

 

Regarding foreach as i know how to use with one or two dimensional arrays but there is not any example that show to access the array of type i have given above thats why i am facing problems

so $this->test['testing'] contains a multidimensional array. You'll need to do a foreach within a foreach

foreach($this->test['testing'] as $array)
{
    foreach($array as $key => $value)
    {
        // do something
    }
}

If thats not what you want you'll need to explain more clearly what you're trying to do and post what code you have tried.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.