[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2013-01-19
3
Medium Priority
?
290 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 111

Accepted Solution

by:
Ray Paseur earned 1000 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 1000 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 111

Expert Comment

by:Ray Paseur
ID: 38798282
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

649 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