Skip to main content

PHP

Sort a multidimensional array in PHP?

the most challenge question in the past was soring a multidimensional arrays in PHP, now lets make it in an easy way

You have your array like this 

 

$array = [];
$array[] = array('name' => 'name1', 'age' => 85);
$array[] = array('name' => 'name2', 'age' => 15);
$array[] = array('name' => 'name3', 'age' => 10);
$array[] = array('name' => 'name4', 'age' => 59);

the easy way is to use these command 

 

Merge text files using PHP code

the easiest and best way is to use the below code

 

<?php

$txt1 = file_get_contents('1.txt');
$txt1 .= "\n" . file_get_contents('2.txt');
$txt1 .= "\n" . file_get_contents('3.txt');

$fp = fopen('newText.txt', 'w');
if(!$fp)
    die('Could not create / open text file for writing.');
if(fwrite($fp, $txt1) === false)
    die('Could not write to text file.');

echo 'Text files have been merged.';

?>

Magento 2 Allowed Memory exhausted error when compile code

you need to increase the memory_limit in php.ini

and as a quick solution you can use these commands directly in the command line

 

php -dmemory_limit=5G bin/magento setup:di:compile

and 

php -dmemory_limit=5G bin/magento setup:static-content:deploy

 

 

another code for the composer update

php -dmemory_limit=5G composer.phar update

php -d memory_limit=-1 /usr/local/bin/composer update
 

 

PHP 7.2 and use it instead of PHP 7.3 in Mac OS Catalina

- Install Homebrew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

- brew install [email protected]

- echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile

- echo 'export PATH="/usr/local/opt/[email protected]/sbin:$PATH"' >> ~/.bash_profile

- source ~/.bash_profile

-open /private/etc/apache2/httpd.conf

- add this line "LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so"

PhpStorm disable auto-save

How to disable auto-save:

  • Go to File > Settings (Ctrl+Alt+S).
  • Go to Appearance & Behavior > System Settings.
  • unchecked: the both fields
    • Save files on frame deactivation
    • Save files automatically if application is idle for x sec.
  • Go to Editor > General > Editor Tabs
  • Put a checkmark on
    • "Mark modified files with asterisk"

Click Apply > OK.

That's it.