Checking if the array contains same type variables like all numeric in php

I was in need of checking if the given array is all numeric or not. A colleague suggested with snippet the use of array_reduce – here the implementation

$numbers = array(1,22, 7, 34, 20);
$all_numbers = array_reduce($numbers, function($val1, $val2){
   return $val1 && is_numeric($val2);
}, TRUE);

Should do the trick.
zaTisIT!!

was not found in the haystack error for select element in zend

You might get this error while working on zend form which has select element on it.

And most probably you are messing with this element on your controller or from your front end friend javascript [ that was in my case ]

Just put the following in the controller and you should be fine


$form->getElement('selectElementNameHere')->setRegisterInArrayValidator(FALSE);

This is a behavior of zend adding a default validator of inarray.
You would find more detailed explanation on zend website.

Learn node js angular and mongodb with simple step by step tutorials here

Run php from command line without script file

Do you want to run a quick php script, a line or two, without having file? Thanks for PHP’s cute command line option you can do that.
If you have some file the way to run it, as you know would be

php file.php

But without file if you want to run a simple function like date then use -r option

php -r "echo date();"

would do the trick

Also if you want to get explanation on some built-in function

php --rf strtoupper

would give you an explanation that is something like

Function [  function strtoupper ] {

  - Parameters [1] {
    Parameter #0 [  $str ]
  }
}

For more use php –help!!

Cannot send session cache limiter – headers already sent Error in php Session

Well, Session have both plus and minus parts, but we do use them largely in PHP. So, while developing have you come across Cannot send session cache limiter – headers already sent error but you can’t find any echoed part on the given file? I have got this problem and found out that there is a left over space at the end of the file.
So check if you have spaces either at the beginning or at the end of your file and remove that.

Render hidden element with out decorator in Zend Framework

When you add hidden element on the zend form, you would see the hidden elements taking up places wrapped by dt dd tags.
To get rid of that and view only the hidden element, do:
$form->addElement(‘hidden’, ‘somename’, array(‘decorators’=>’ViewHelper’)); – this would render it without the decorators.

Regex for individual words in php

This is a simple check for words that you might want to check if the given string is this word or that word. Possible utilization could be: when you allow the user to upload file, you might want to get only certain type of file only like in the case of image jpeg, jpg, and gif only

if (preg_match('/jpeg|jpg|gif/i')){
   //do uploading
}else{
    $message = "supported file types are ...";
}

CSS rendered different for local and remote servers

I was banging against the wall for this weirdest scenario.

When I run my site locally using the localhost, http://localhost/site.., all is good and the desired width and everything is OK.

When I publish my site on my server, all the CSS were jacked as if I have never tried it on my local machine before I publish it.

The browser is the same, the css and everything is the same but the rendering is different from local machine.

Trying to figure out, when I access my local site from my other computer, it is still jacked .. I said “HA!”.

Then I changed the localhost with my computer name and yup it is all messed up.
Tried to find out why apache is acting nice for local and strange for the other ones. But at least I can work on my local machine and publish it now.

Also, check if you have any reference of the css and javascript files with localhost.