Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of [] [closed]

Tags:

arrays

php

I have a code as below and I am not sure what type of data variable $ACTIVITYGROUPS[] has and how do I read it ?

$ACTIVITYGROUPS[] = saprfc_table_read ($fce, "ACTIVITYGROUPS", $i);

When I did print_r(saprfc_table_read ($fce, "ACTIVITYGROUPS", $i); I got bunch of arrays without any seperator and not sure how to exactract the data. can someone tell me what does it do in above sentences ?

Here is what print_r(saprfc_table_read ($fce, "ACTIVITYGROUPS", $i); result gives me:

Array (
    [AGR_NAME] => Y:SECURITY_DISPLAY
    [FROM_DAT] => 20080813
    [TO_DAT] => 99991231
    [AGR_TEXT] => Security Display - Users & Roles
    [ORG_FLAG] => C
)

Array (
    [AGR_NAME] => Y:SECURITY_ADMIN_COMMON
    [FROM_DAT] => 20080813
    [TO_DAT] => 99991231
    [AGR_TEXT] => Security Administrator
    [ORG_FLAG] => C
)

Array (
    [AGR_NAME] => Y:LOCAL_TRANSPORT
    [FROM_DAT] => 20090810
    [TO_DAT] => 99991231
    [AGR_TEXT] => Transport into target client - DEV system only
    [ORG_FLAG] =>
)
like image 424
Lord OfTheRing Avatar asked Aug 03 '11 21:08

Lord OfTheRing


People also ask

What is the meaning of closed on?

Definition of close on : to formally and legally agree to and complete (an important financial arrangement, such as the purchase of a house) We're going to close on our house next Friday. They closed on the deal.

What is the meaning of Clise?

A cliché is an idea or phrase which has been used so much that it is no longer interesting or effective or no longer has much meaning. [disapproval] I've learned that the cliche about life not being fair is true. [ + about] It's a cliche but true that pubs are the lifeblood of many communities.

What is the other meaning of closed?

1a : to move so as to bar passage through something Close the gate. b : to block against entry or passage close a street. c : to deny access to The city closed the beach. d : to suspend or stop the operations of close school —often used with down They closed down the factory. e : screen, exclude close a view.

What is the meaning of closed and open?

open and close means the preparation of the grave or niche for interment and completing and closing the grave after the interment.


2 Answers

[] means push - put the given argument as a new element on the end of the array. That means that $ACTIVITYGROUPS is an array*.

$arr = array();
$arr[] = 1;       // Put 1 in position 0
$arr[] = "a";     // Put "a" in position 1
$arr[] = array()  // Put a new, empty array in position 2

As stated by the PHP docs, array_push has the same effect as [].


* If it's not an array, using [] will give you a syntax error:

Warning: Cannot use a scalar value as an array in test.php on line 4

like image 186
Nicole Avatar answered Oct 15 '22 16:10

Nicole


In many languages the [] notation stands for an array. Is the same as php's array_push(): it pushes an element in the variable that has [] at the end.

If the variable is null, you can consider the square brackets like a declaration of an array.

The same notation of push applies to Javascript, for example. When using it like $var[] = 'a'; what happens is the same as array_push() I was talking above. Just finds the next position in the array and adds there your value.

An array can be walked with for, foreach, while, do while and you can check it's contents with print_r() or var_dump() functions.

like image 44
Bogdan Constantinescu Avatar answered Oct 15 '22 15:10

Bogdan Constantinescu