Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to understand PHP syntax when it's explained "in theory" on php.net?

Tags:

php

I'm reading php.net in order to get acquainted with new functions. I'm very newbie in learning any programming language, and when I read how any function's syntax is explained, it's not easy for me. ie: array_unshift() I get this:

int array_unshift(array array, mixed variable [,mixed variable...])

I read some examples, but I can't understand a priori [ed note: not having any prior knowledge] how the syntax works reading only the theoretical explanation. I haven't found any other question related to this.

like image 626
Rosamunda Avatar asked Apr 17 '26 00:04

Rosamunda


2 Answers

You've misquoted the function definition, it is:

int array_unshift ( array &$array , mixed $value1 [, mixed $... ] )

which equates to:

return_type function_name ( type_hint $arg_name , type_hint $arg_name [, type_hint $...] )

where ... means it will accept as many more arguments as you want to throw at it.

like image 116
Sammitch Avatar answered Apr 18 '26 15:04

Sammitch


This can easily be narrowed done to the following

  1. return value: int
  2. name of the method: array_unshift
  3. list of accepted arguments:
    1. first argument:
      • type: array
      • name that will be used in the description, etc.: array
    2. second argument:
      • type: mixed (multiple types possible)
      • name that will be used in the description, etc.: variable

You can read more about the types in the manual.

like image 35
kero Avatar answered Apr 18 '26 15:04

kero



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!