[php] PHP and arrays

Kevork Krozian kevork at edulists.com.au
Sun Jul 31 10:33:24 EST 2011


Hi PHP folks,

 

With the current Software development SAC covering 2D arrays as one possible
data structure to use in the assessment  I thought  I would mention the
flexibility ( or weak language type ) of PHP that allows for creativity in
the data the array can hold. Eg.

 

<?php

$myarray =array('apple',55, array('plum','peach','apricot'),true,'54.56');


$myarray[4]= 5*$myarray[4];

print_r($myarray);

?>

// Note the data types in the array- string, integer, array of string,
Boolean and real/float. 

 

PHP handles mixed data types in an array and simply adjusts the data type
when an operator is applied as the example attempting to multiply 5* '54.56'
to give 278.2 shown below.  Notepad++ shows the data types in the
highlighting it uses as shown here:

 



 

Output is

 

Array ( [0] => apple [1] => 55 [2] => Array ( [0] => plum [1] => peach [2]
=> apricot ) [3] => 1 [4] => 272.8

 

Note the string '54.56' is happily multiplied by 5 to give the float/real
272.8.

The point is that a 2D array of mixed data types could happily be
implemented in PHP to give a bit more meaning to a problem setting than all
data to be the same.

Add a search and a sort and I believe you have met the problem complexity of
the task.

 

 

Kind Regards

 

Kevork Krozian

Edulists Creator Administrator

www.edulists.com.au

tel: 0419 356 034

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.edulists.com.au/pipermail/php/attachments/20110731/23d4b350/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 7464 bytes
Desc: not available
Url : http://www.edulists.com.au/pipermail/php/attachments/20110731/23d4b350/attachment.png 


More information about the php mailing list