Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


<help wanted> best practice to define an array filter_list
Author
Message
<help wanted> best practice to define an array #1
what is the way that I could define an array:
1.
PHP Code:
$arrayTest [1] ="one";
$arrayTest [2] ="two"

2.
PHP Code:
$arrayTest = array(1=>"one",2="two"); 

thanks

Reply

RE: <help wanted> best practice to define an array #2
well the main advantage of option 2 is that it ensures that the array has no other unexpected values in it. My personal preference for laying out arrays with a lot of initial entries is:

PHP Code:
$arrayTest = array(
    
=> 'one',
    
=> 'two',
    
=> 'three',
    
=> 'four',
    
=> 'five',
    ); 


I also always add a comma at the end of the last entry. PHP will ignore it and I won't forget it when I go to add another item to the end of the list!

so i suggest to use the second option !

Reply

RE: <help wanted> best practice to define an array #3
An array in PHP is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be other arrays, trees and multidimensional arrays are also possible.
PHP Code:
<?php
$a
=array("a"=>"Dog","b"=>"Cat","c"=>"Horse");
print_r($a);
?>
<?php echo "Very inactive at this current moment in time"; ?>
[Image: Z8KDe.png]

Reply

RE: <help wanted> best practice to define an array #4
geez guys
i just got fastest reply since ever

Grand thanks both of you

Reply

RE: <help wanted> best practice to define an array #5
(11-18-2012, 12:27 AM)jabberwock Wrote: geez guys
i just got fastest reply since ever

Grand thanks both of you

he he
well what can i said ..
may the PHPknowledge be with you =))

Reply

RE: <help wanted> best practice to define an array #6
As said above, you can do that... And just one thing I'd like to tell you..
PHP has a very good advantage... You can set arrays using this :
PHP Code:
$arraytest range(1,100); 

It initializes all the values from 1 to 100 in the array...

You may use it sometimes..

Reply

RE: <help wanted> best practice to define an array #7
Gosh that freakin blue messes with my eyes...

Reply







Users browsing this thread: 1 Guest(s)