BostonGuru
10-11-2006, 07:43 PM
I have a huge 2 dimensional php array, and I am wondering if there is a way to print out the dimensions (widthxheight) of this array.
![]() | View Full Version : Get size of array dimensions BostonGuru 10-11-2006, 07:43 PM I have a huge 2 dimensional php array, and I am wondering if there is a way to print out the dimensions (widthxheight) of this array. Googled 10-11-2006, 10:52 PM Could you be more specific how your Array is built. Array { "Width" => Array { "height" } } ??? There may be lots of possiblities, show us a bit more. Regards, G BostonGuru 10-11-2006, 10:59 PM Thanks for the response. the array SHOULD be 12,000 values by about 20 values it is built by this method: for($i=0;$i<$datarows;$i++) { for($h=0;$h<12000;$h++) { $array[$i][$h]=$value; } } The reason I want to get the dimensions is because after the script runs I serialize() the array, the save the string to a text file. Then when I read the string in using: $array = unserialize(file_get_contents("array.txt",1)); something is messed up. Googled 10-11-2006, 11:04 PM May I ask what are you trying to do ? May help find a suitable answer to your needs. I don't think this is the right approach to create a 2 dimensional array with a static value. Regards, G BostonGuru 10-11-2006, 11:10 PM its actually not a static value. there are a whole bunch of instructions for each value which calculates the end $value. Basically I am working on image manipulation and trying to store pixel values in an array: 20 images, of 12,000 pixels each. awsolutions 10-11-2006, 11:21 PM print_r($array) if php Googled 10-11-2006, 11:56 PM I see.. Try using a simple 2 dimensionnal array then serialize it, write it to a file, then read it, unserialize it and see if it works. The problem may be elsewhere. Or it may be a maximum size problem. The only way to get over it is to find out what cause the problem by trying with simple data. Regards, G BostonGuru 10-12-2006, 09:34 AM Yea thats what i have been doing, but somewhere in the serialize/unserialize process my array is getting corrupted. BostonGuru 10-12-2006, 10:47 AM It looks like when reading in the string it stops at 3637 characters. Does anyone else know anything of this? Googled 10-12-2006, 12:07 PM Hi, never heard of this problem before. Try to get your file's content using fopen(), fread(), fclose(). Let me know it it worked. Regards, G gplhost 10-12-2006, 01:43 PM It's VERY easy: $size_x = sizeof($array); $size_y = sizeof($array[0]); Thomas BostonGuru 10-12-2006, 03:06 PM Thanks for answering my origional questions qpl; this will def. help with my debugging. Googled, I tried using fread but had a similar problem. What I ended up doing was: $saveWeight2 = "<?php \n"; for($h=0;$h<$counter2;$h++) { for($i=0;$i<$counter1;$i++) { $random = rand(1,1000)/1000; $saveWeight2.='$weight2['; $saveWeight2.=$i; $saveWeight2.=']['; $saveWeight2.=$h; $saveWeight2.=']='; $saveWeight2.=$random; $saveWeight2.="; \n"; } } $saveWeight2.="?>"; I can then save that string to a .php textfile, and then retrieve the large array by using 'include weightfile.php'. |