PHP Classes

great

Recommend this page to a friend!

      Multidim  >  All threads  >  great  >  (Un) Subscribe thread alerts  
Subject:great
Summary:serialization
Messages:3
Author:Pashkov Denis Igorevich
Date:2011-01-27 15:08:43
Update:2011-01-27 17:11:17
 

  1. great   Reply   Report abuse  
Picture of Pashkov Denis Igorevich Pashkov Denis Igorevich - 2011-01-27 15:08:44
Great!. But is that faster than serialization ?

  2. Re: great   Reply   Report abuse  
Picture of troy knapp troy knapp - 2011-01-27 16:56:33 - In reply to message 1 from Pashkov Denis Igorevich
I'm not entirely sure what you are asking, but I hope the following responce will clear things up...

Multidim's purpose is not to represent an array, but to manipulate it. If you want to serialize an array and store it in a database in a single field, then that would certainly be faster... but it would be much harder to manipulate the contents.

The slowest part of Multidim is the insert statement. Keep in mind what it's doing... if you have an array like:
array(
[0]=>array([0]=>'foo', [1]=>'bar', [2]=>123),
[1]=>array([0]=>'foo1', [1]=>'bar1', [3]=>21),
[2]=>array([0]=>'foo2', [1]=>'bar3', [2]=>890)
)

Multidim will conduct 3 inserts (one for each root array element). Now if you were to serialize the above array and insert it into a database, as one row, then it is trivially true that serialization would take less time. Even with the added mysqli_multi_query() functionality, serialization would take much less time.

However, if you were to take said serialized array and try to parse it and, for example, delete all elements in an array when the second order array element 2 (in other words: $temp=array[0]; target_filter_element=$temp[2])is greater than 21, multidim would do THAT much faster, and much more easily than the alternative.

Basically, I found myself creating 2 dimensional arrays all the time, and trying to interpret the data contained within. Multidim is especially optimized to help you in those kinds of cases.

  3. Re: great   Reply   Report abuse  
Picture of troy knapp troy knapp - 2011-01-27 17:11:17 - In reply to message 2 from troy knapp
Btw, forgot to mention sorting... good grief, sorting multidimensional associative arrays can be a huge pain, especially if they are of variable element counts. However, databases do this very easily and efficiently. If you can represent arrays in database form (which is what multidim does) then your sorts can be so much easier and quicker.