How to access a variable across two files

Use: global.php <?php if(!session_id()) session_start(); $filename = “test”; if(!isset($_SESSION[‘filename’])) { $_SESSION[‘filename’] = $filename; } ?> test.php <?php if(!session_id()) session_start(); //include(“global.php”); $_SESSION[‘filename’] = “new value”; ?> test1.php <?php if(!session_id()) session_start(); $filename = $_SESSION[‘filename’]; echo $filename; //output new value ?>

PHP-Sort array based on another array?

For a detailed answer, why array_multisort does not match your needs, view this answer, please: PHP array_multisort not sorting my multidimensional array as expected In short: You want to sort an array based on a predefined order. The Answer is also given over there, but i copied one solution to this answer, too: Use usort … Read more

new mysqli(): how to intercept an ‘unable to connect’ error?

You need to tell mysqli to throw exceptions: mysqli_report(MYSQLI_REPORT_STRICT); try { $connection = new mysqli(‘localhost’, ‘my_user’, ‘my_password’, ‘my_db’) ; } catch (Exception $e ) { echo “Service unavailable”; echo “message: ” . $e->message; // not in live code obviously… exit; } Now you will catch the exception and you can take it from there.

WooCommerce – send custom email on custom order status change

The hook you need is: woocommerce_order_status_changed add_action(“woocommerce_order_status_changed”, “my_awesome_publication_notification”); function my_awesome_publication_notification($order_id, $checkout=null) { global $woocommerce; $order = new WC_Order( $order_id ); if($order->status === ‘completed’ ) { // Create a mailer $mailer = $woocommerce->mailer(); $message_body = __( ‘Hello world!!!’ ); $message = $mailer->wrap_message( // Message head and message body. sprintf( __( ‘Order %s received’ ), $order->get_order_number() ), … Read more

HOW TO: Install Memcache on XAMPP (Windows 7/8/10)

Here are the steps that should be followed when you install memcache. Start your xampp. Click on ‘config’ and open php.ini file. search for ;extension=php_memcache.dll If not found add extension=php_memcache.dll [Memcache] memcache.allow_failover = 1 memcache.max_failover_attempts=20 memcache.chunk_size =8192 memcache.default_port = 11211 Download the file php_memcache.dll from windows.php.net (make sure to check your php version and php_memcache.dll … Read more

find in set in laravel ? example

You need to escape the call to FIND_IN_SET() using quotes: $query = DB::table(‘tags_value’) ->whereRaw(‘FIND_IN_SET(“css”, Tags)’) ->get(); But unless it’s a fixed value, you should always parameterize the column for which you search in FIND_IN_SET: $searchvalue=”css”; $query = DB::table(‘tags_value’) ->whereRaw(‘FIND_IN_SET(?, Tags)’, [$searchvalue]) ->get();