How to access array contents and serialize data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
new_member
Forum Newbie
Posts: 8
Joined: Sat Sep 28, 2013 12:49 am

How to access array contents and serialize data

Post by new_member »

Hi,

I want to access the contents of this particular array :
Array
(
[0] => Array

(
[test] => test1
[test2] => test2

)

[1] => Array

(
[test] => test1
[test2] => test2

)

)

I want to use foreach loop but i dont know how to access the elemens of this kind of array. I have tried a lot but couldnt find any way

Moreover i want to serialze the array

[values] => Array
(
[0] => Array
(
[val1] => val1
[val2] => val2

)

)

i have serialized it using php function serialize on values array but it returns null. Can anyone tell how to do this??
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How to access array contents and serialize data

Post by Celauran »

Code: Select all

foreach ($array as $item) {
    echo $item['test'];
    echo $item['test2'];
}

Code: Select all

$foo = serialize($bar)
What code are you using?
new_member
Forum Newbie
Posts: 8
Joined: Sat Sep 28, 2013 12:49 am

Re: How to access array contents and serialize data

Post by new_member »

i am using simply

serialize($this->values)

printing $this->values gives correct array values but serializing giving empty results
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: How to access array contents and serialize data

Post by AbraCadaver »

Why are you serializing it?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply