I am coding a site and have come across a situation where I need to send a serialized array to a python routine. During this coding I have been printing out results on screen as a debugging aid. Old school I know, but it works.
After I serialize an array I print the array to the screen as I said. During this I have noticed that the contents of the serialized array are not completely correct. Let me explain.
I first serialize a 10 element array and the contents are displayed correctly. I then do a 15 element array and once again the contents are correct. If I then do an array smaller then 15, say 11, then contents are correct up to element 11 but then the array fills up with the contents (12-15) from the 15 element array.
Here is a copy of what happens:
LR: RUN LOGISTIC REGRESSION ON THIS DATASET: DExcode trigger 2
(2,0)(2,0)(2,0)(2,0)(2,0)(3,1)(2,2)(4,0)(2,0)(4,1)(3,0)(3,1)(4,2)(4,1)(3,1)
LR: SEND SERIALIZED DATA TO headachestats.py:
a:15:{i:0;a:2:{i:0;s:1:"2";i:1;s:1:"0";}i:1;a:2:{i:0;s:1:"2";i:1;s:1:"0";}i:2;a:2:{i:0;s:1:"2";i:1;s:1:"0";}i:3;a:2:{i:0;s:1:"2";i:1;s:1:"0";}i:4;a:2:{i:0;s:1:"2";i:1;s:1:"0";}i:5;a:2:{i:0;s:1:"3";i:1;s:1:"1";}i:6;a:2:{i:0;s:1:"2";i:1;s:1:"2";}i:7;a:2:{i:0;s:1:"4";i:1;s:1:"0";}i:8;a:2:{i:0;s:1:"2";i:1;s:1:"0";}i:9;a:2:{i:0;s:1:"4";i:1;s:1:"1";}i:10;a:2:{i:0;s:1:"3";i:1;s:1:"0";}i:11;a:2:{i:0;s:1:"3";i:1;s:1:"1";}i:12;a:2:{i:0;s:1:"4";i:1;s:1:"2";}i:13;a:2:{i:0;s:1:"4";i:1;s:1:"1";}i:14;a:2:{i:0;s:1:"3";i:1;s:1:"1";}}
LR: RUN LOGISTIC REGRESSION ON THIS DATASET: DExcode trigger 1
(2,0)(2,1)(3,1)(3,0)(4,0)(2,2)(3,0)(3,0)(4,0)(3,0)(3,1)(2,0)(2,0)(2,0)(3,1)(4,1)(3,0)(3,2)(4,1)(4,2)(4,1)
LR: SEND SERIALIZED DATA TO headachestats.py:
a:21:{i:0;a:2:{i:0;s:1:"2";i:1;s:1:"0";}i:1;a:2:{i:0;s:1:"2";i:1;s:1:"1";}i:2;a:2:{i:0;s:1:"3";i:1;s:1:"1";}i:3;a:2:{i:0;s:1:"3";i:1;s:1:"0";}i:4;a:2:{i:0;s:1:"4";i:1;s:1:"0";}i:5;a:2:{i:0;s:1:"2";i:1;s:1:"2";}i:6;a:2:{i:0;s:1:"3";i:1;s:1:"0";}i:7;a:2:{i:0;s:1:"3";i:1;s:1:"0";}i:8;a:2:{i:0;s:1:"4";i:1;s:1:"0";}i:9;a:2:{i:0;s:1:"3";i:1;s:1:"0";}i:10;a:2:{i:0;s:1:"3";i:1;s:1:"1";}i:11;a:2:{i:0;s:1:"2";i:1;s:1:"0";}i:12;a:2:{i:0;s:1:"2";i:1;s:1:"0";}i:13;a:2:{i:0;s:1:"2";i:1;s:1:"0";}i:14;a:2:{i:0;s:1:"3";i:1;s:1:"1";}i:15;a:2:{i:0;s:1:"4";i:1;s:1:"1";}i:16;a:2:{i:0;s:1:"3";i:1;s:1:"0";}i:17;a:2:{i:0;s:1:"3";i:1;s:1:"2";}i:18;a:2:{i:0;s:1:"4";i:1;s:1:"1";}i:19;a:2:{i:0;s:1:"4";i:1;s:1:"2";}i:20;a:2:{i:0;s:1:"4";i:1;s:1:"1";}}
LR: RUN LOGISTIC REGRESSION ON THIS DATASET: Got very hungry at some point in past 24 hours.
(4,0)(4,0)(4,1)(4,2)(4,0)(4,1)(4,2)(4,0)(4,0)(4,1)(4,0)(4,2)(4,1)(4,1)
LR: SEND SERIALIZED DATA TO headachestats.py:
a:21:{i:0;a:2:{i:0;s:1:"4";i:1;s:1:"0";}i:1;a:2:{i:0;s:1:"4";i:1;s:1:"0";}i:2;a:2:{i:0;s:1:"4";i:1;s:1:"1";}i:3;a:2:{i:0;s:1:"4";i:1;s:1:"2";}i:4;a:2:{i:0;s:1:"4";i:1;s:1:"0";}i:5;a:2:{i:0;s:1:"4";i:1;s:1:"1";}i:6;a:2:{i:0;s:1:"4";i:1;s:1:"2";}i:7;a:2:{i:0;s:1:"4";i:1;s:1:"0";}i:8;a:2:{i:0;s:1:"4";i:1;s:1:"0";}i:9;a:2:{i:0;s:1:"4";i:1;s:1:"1";}i:10;a:2:{i:0;s:1:"4";i:1;s:1:"0";}i:11;a:2:{i:0;s:1:"4";i:1;s:1:"2";}i:12;a:2:{i:0;s:1:"4";i:1;s:1:"1";}i:13;a:2:{i:0;s:1:"4";i:1;s:1:"1";}i:14;a:2:{i:0;s:1:"3";i:1;s:1:"1";}i:15;a:2:{i:0;s:1:"4";i:1;s:1:"1";}i:16;a:2:{i:0;s:1:"3";i:1;s:1:"0";}i:17;a:2:{i:0;s:1:"3";i:1;s:1:"2";}i:18;a:2:{i:0;s:1:"4";i:1;s:1:"1";}i:19;a:2:{i:0;s:1:"4";i:1;s:1:"2";}i:20;a:2:{i:0;s:1:"4";i:1;s:1:"1";}}
I use this command to serialize the array:
$sarr = serialize($logRegArray); // $sarr stands for serialized-array
and this to print it:
print_r($sarr);
A full printout can be seen here:
http://hpashler.webfactional.com/analyz ... 160409.php
What I need to do is send a number of 2-dimensional arrays to a python routine. I need to send each array separately and I need to serialize the array before I send it.
Do I need to reset the serialized array or what am I doing wrong?
Any help in this situation would be appreciated.
Need help with serialize()
Moderator: General Moderators
Re: Need help with serialize()
Thank you for your reply. I discovered the problem was that I was not resetting the array that I had used to store the results. All is fixed now.