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??

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.