Print variable types: Difference between revisions

Jump to navigation Jump to search
Line 39: Line 39:


== Print the variable ==
== Print the variable ==
PHP
=== PHP ===
* [http://php.net/manual/en/function.print-r.php PHP: print_r - Manual] or  
* [http://php.net/manual/en/function.print-r.php PHP: print_r - Manual] or  
* [http://php.net/manual/en/function.var-dump.php PHP: var_dump - Manual]
* [http://php.net/manual/en/function.var-dump.php PHP: var_dump - Manual]
Line 50: Line 50:
</pre>
</pre>


Python
=== Python ===
* [https://www.python-course.eu/python3_print.php Python3 Tutorial: Output with Print]
* [https://www.python-course.eu/python3_print.php Python3 Tutorial: Output with Print]
* [https://stackoverflow.com/questions/1987694/how-to-print-the-full-numpy-array python - How to print the full NumPy array? - Stack Overflow]
* [https://stackoverflow.com/questions/1987694/how-to-print-the-full-numpy-array python - How to print the full NumPy array? - Stack Overflow]
Line 58: Line 58:


print(var)) # python v. 3
print(var)) # python v. 3
</pre>
== Iterate over elements of an array or list ==
=== PHP ===
PHP: Using [http://php.net/manual/en/control-structures.foreach.php foreach] to iterate over elements of an array or public properties of an object<ref>[http://www.zentut.com/php-tutorial/php-foreach/ Using PHP foreach Loop to Iterate over Elements of an Array]</ref>.
Code:
<pre>
# type: array
$animals = ["bird", "dog", "bird"];
foreach ($animals as $index => $animal) {
  print "$index $animal"  . PHP_EOL;
}
</pre>
Result:
<pre>
0 bird
1 dog
2 bird
</pre>
=== Python ===
Code:
<pre>
# type: list
animals = ['cat', 'dog', 'bird']
for index, animal in enumerate(animals):
    print (index, animal)
</pre>
Result:
<pre>
0 bird
1 dog
2 bird
</pre>
</pre>


Navigation menu