We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,124 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Which of the following correctly sets up a PHP array?

Which of the following correctly sets up a PHP array??

  1. array() = $array_values[];

  2. $array_values = array();

  3. array() = $array_values[];

  4. $array_values = new array();

4
Contributors
5
Replies
3 Hours
Discussion Span
10 Months Ago
Last Updated
7
Views
Question
Answered
napninjanx
Junior Poster in Training
51 posts since Jul 2012
Reputation Points: 0
Solved Threads: 1
Skill Endorsements: 0

I think It's 2 right?

napninjanx
Junior Poster in Training
51 posts since Jul 2012
Reputation Points: 0
Solved Threads: 1
Skill Endorsements: 0

Yes, here you can find more information: http://php.net/manual/en/language.types.array.php

cereal
Veteran Poster
1,145 posts since Aug 2007
Reputation Points: 344
Solved Threads: 222
Skill Endorsements: 22
$array = array();

you don't need to declare before hand either you can use:

$array[] = $value;//add to end
$array[2] = $value;//add/overwrite entry with key of 2

1, 3 and 4 are wrong in php, 4 is the javascript to declare an array and 2 is correct

Biiim
Posting Pro
504 posts since Oct 2011
Reputation Points: 104
Solved Threads: 83
Skill Endorsements: 7

yeap...2 is correct.

JorgeM
Industrious Poster
4,018 posts since Dec 2011
Reputation Points: 297
Solved Threads: 548
Skill Endorsements: 115

Thanks for the info.

napninjanx
Junior Poster in Training
51 posts since Jul 2012
Reputation Points: 0
Solved Threads: 1
Skill Endorsements: 0
Question Answered as of 9 Months Ago by Biiim, JorgeM and cereal

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1223 seconds using 2.78MB