Php Print Array

A comment on arraymerge mentioned that arraysplice is faster than arraymerge for inserting values. This may be the case, but if your goal is instead to reindex a numeric array, arrayvalues is. This video shows you how to print an array in PHP.Download link to the PHP code: http://iturl.nl/snzxi.

  1. Php Print Array Values
  2. Php Print Array Object
  3. Php Print Array Contents

Being able to quickly or efficiently get the keys from an array which is most likely an API call is great. You can see what data exists which may not be clear in the docs (if they exist).

Here is a method with PHP to print out an array keys and values, you can even shape the loop to create a CREATE TABLE query using the keys for column names or even creating an INSERT query.

This example i am using the Reddit API, this is a multi dimensional array and you can see for the foreach i further define the row for which i want to get the keys and values for.

Printing array keys & values

Php print array keys

The basic code with no formatting or style is:

[0]['data']['children'][0]['data'] points to the part with the keys i am after. Load up the http://www.reddit.com/r/pics/c1wqkk.json call in a json formatter to see multi dimensions to this call.

If you run the code above you will notice a few errors for trying to parse arrays, that is because there is still another layer (dimension) you can go into. However these are mostly always empty for this call.

The booleans also do not get displayed (true and false), nor empty strings (“”).

Formatting and adding style

Php print array elements

Php Print Array Values

To add some formatting to display the values accurately for their type here is an added function plus a little bit of CSS to make readability better:

Php Print Array Object

This looks like

Contents

PHP array push: Main Tips

  • PHP array_push() function is used to insert new elements into the end of an array and get the updated number of array elements.
  • You may add as many values as you need.
  • Your added elements will always have numeric keys, even if the array itself has string keys.
  • PHP array push function has been introduced in PHP 4.

array_push() Explained

This function is used to insert elements into the end of an array. Here is a simple example to get you started:

Learn Correct Syntax

To have PHP array push function executed correctly, you have to follow this syntax:

array_push(array,value1,value2..);

Php Print Array

In the table below, the parameters used in the PHP array push function are explained one by one: Tractor simulator game.

ParameterDescription
arrayNecessary. Defines an array.
value1Necessary. Defines the value to add.
value2Optional. Defines the next values to add.

Example

Php Print Array Contents

Look at the code below. You can see an array that contains string keys. Let's see how two new values are added at the end of it using PHP array push function: