new_member Posted September 27, 2013 Share Posted September 27, 2013 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?? Quote Link to comment https://forums.phpfreaks.com/topic/282482-how-to-get-the-array-contents-and-serialize-data/ Share on other sites More sharing options...
requinix Posted September 27, 2013 Share Posted September 27, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/282482-how-to-get-the-array-contents-and-serialize-data/#findComment-1451447 Share on other sites More sharing options...
new_member Posted September 27, 2013 Author Share Posted September 27, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/282482-how-to-get-the-array-contents-and-serialize-data/#findComment-1451451 Share on other sites More sharing options...
requinix Posted September 27, 2013 Share Posted September 27, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/282482-how-to-get-the-array-contents-and-serialize-data/#findComment-1451452 Share on other sites More sharing options...
new_member Posted September 27, 2013 Author Share Posted September 27, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/282482-how-to-get-the-array-contents-and-serialize-data/#findComment-1451455 Share on other sites More sharing options...
Ch0cu3r Posted September 27, 2013 Share Posted September 27, 2013 but there is not any example that show to access the array of type i have given above thats why i am facing problems Its the same format foreach($this->test['testing'] as $key => $value) { // do whatever } Quote Link to comment https://forums.phpfreaks.com/topic/282482-how-to-get-the-array-contents-and-serialize-data/#findComment-1451458 Share on other sites More sharing options...
new_member Posted September 28, 2013 Author Share Posted September 28, 2013 How to loop through this type of array? Array ( [0] => Array ( [test] => test1 [test2] => test2 ) ) Quote Link to comment https://forums.phpfreaks.com/topic/282482-how-to-get-the-array-contents-and-serialize-data/#findComment-1451503 Share on other sites More sharing options...
Ch0cu3r Posted September 28, 2013 Share Posted September 28, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/282482-how-to-get-the-array-contents-and-serialize-data/#findComment-1451526 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.