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
Solved

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

Posted on 2013-01-19
3
279 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
  • 2
3 Comments
 
LVL 109

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 109

Expert Comment

by:Ray Paseur
ID: 38798282
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 …

860 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