Solved

What does the "0" mean in this PHP excerpt?

Posted on 2013-01-19
3
283 Views
Last Modified: 2013-03-09
I am learning from a book called "Head First PHP and MYSQL"

One of the lessons has this line written in it:

$category_totals = array(array($mismatch_categories[0], 0));

Open in new window


if you have array($variable[0],0)  what does the second zero do?

Thanks
0
Comment
Question by:NewWebDesigner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 38796948
$category_totals is assigned to be an array of one element

Inside that array is another array of two elements
    The first element is the zero-th position of the array $mismatch_categories
    The second element is the integer zero

It may be easier to understand if you write it out line-by-line with indenting like this:

$category_totals = array
( array
  ( $mismatch_categories[0]
  , 0
  )
)
;

Open in new window


HTH, ~Ray
0
 
LVL 34

Assisted Solution

by:Slick812
Slick812 earned 250 total points
ID: 38797771
also it is much better for me to understand if I do it as it should be done as -
 $insideArray = array($mismatch_categories[0],  0);     // two array elements, , 0 as mismatch and 1 as  0
 echo "Second element is ".$insideArray[1];  // will output "Second element is 0"

//now add to $category_totals
$category_totals = array( $insideArray );

if you want to create an array, you add "Elements" as things you want to get out of array later, arrays are a kind of compartment storage area, each thing between the commas goes into the array as an element |compartment, , data segment| so you can use numbers to get them out later.

you use line of -
$category_totals = array(array($mismatch_categories[0], 0));

is code that works well , but is considered short cut code because it does not create the first array before it creates the second, does all in one line.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 38798282
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question