Showing posts with label arrays. Show all posts
Showing posts with label arrays. Show all posts

Aug 28, 2015

CakePHP and PHP version

I was trying to code at my project. It was OK on my localhost webserver. But... when I moved the files on the real webserver I had a problem.
I didn't know what could that be. I got errors just on some pages. Not at all pages of my website.
Then, I realized that, perhaps, my version of PHP could be too old. Actually, not my version but real webserver version.

Indeed, the problem it was with PHP version which is 5.3 and this version doesn't know about the arrays declared like this:

$ar = ['key1' => 'value1', 'key2' => 'value2'];

It knows only like this:

$ar = array('key1' => 'value1', 'key2' => 'value2');

I got this issue when I tried to make a Form and I finished to have this PHP code

echo $this->Form->input('name', [
                'label'=>[
                    'class' =>  'ContactInput',
                    'text'  =>  'Name:' . $messgError['name']
                ]

            ]);



Aug 3, 2010

PHP - print array

I you want to print an array values you can use next PHP function:

print_r();

Ex:
<?php
$a[] = "0";
$a[] = "5";
$a[] = "mmm';

print_r($a); //this will return function values...
?>