Category : PHP



How to add prefix in each key of PHP Array?

Whenever you require to add one character or more to each and every key of array then most of the people would like prefer add key using for loop or foreach loop. But we can do this without using any kind of loop. using array_combine(), array_keys() and array_map() through we can add prefix on each key of array, In Bellow example you can see how to use both function together and add faster way to add prefix of every item key: <strong>Example:</strong> <pre class="language-php"> $myArray = ['0'=>'Hi','1'=>'Hello','2'=>'Hey']; $myNewArray = array_combine( array_map(function($key){ return 'a.....

By Hardik Savani | February 13, 2016 | | 6974 Viewer | Category : PHP
READ MORE

How to get minimum key value of array in PHP?

Sometimes, you need to get minimum key value of your array but you try to get with loop and any function etc, but in bellow example you can see we can get smallest key value from our php array by using min() and array_keys(). So, let's try to use in your code this way: <strong>Example:</strong> <pre class="language-php"> $myArray = ['2'=>'Hey','4'=>'Hello','1'=>'Hi','3'=>'GH']; $new_key = min(array_keys($myArray)); $new_val = $myArray[$new_key]; print_r($new_val); </pre>

By Hardik Savani | February 12, 2016 | | 1005 Viewer | Category : PHP
READ MORE

How to set scroll to bottom in jquery?

Sometimes, we need to set scroll bottom as default by using jquery, in bellow example you can see i use scrollHeight for get the total height of scroll class div with scroll, and at last i use animate with scrollTop attribute and set bottom, So Basically when your page will load then automatically scroll as bottom. <strong>Example:</strong> <pre class="code language-html"> <html lang="en"> <head> <title>Scroll Down bottom</title> <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> </head> <body> <div cl.....

By Hardik Savani | February 11, 2016 | | 3661 Viewer | Category : PHP
READ MORE

How can i print php variable in jquery?

If you are working on php and you need to print your php variable inside the javascript then you can simple get value. you can use "" for get value of php variable. in following example you can see : <strong>Example:</strong> <pre class="code language-html"> <script type="text/javascript"> var my_var = "<?php echo $my_variable; ?>"; console.log(my_var); </script> OR <script type="text/javascript"> var my_var = <?php echo $my_variable; ?>; console.log(my_var); </script> </pre> But, you can use on php file, Not on js file.

By Hardik Savani | February 8, 2016 | | 1804 Viewer | Category : PHP
READ MORE

How to get product using rakuten marketing api in PHP?

In this post you can find how can use rakuten linkshare API in our php website. first you need to create class for retrieve data from "https://pubhelp.rakutenmarketing.com/hc/en-us" website. now i give to example of product search, but if you use this class then you can easy to implement your other search like advance search etc. So now i am giving you class that send request to rakutenmarketing.com website and get data. but this class you can also you for other site API use like CJ API. <strong>Your php file :</strong> <pre class="language-php"> public function getProduct() { // Bearer to.....

By Hardik Savani | February 6, 2016 | | 10028 Viewer | Category : PHP
READ MORE

PHP: How to count files in folder?

In PHP, you are work on php and you want to need display count number of files in specific folder then you do, glob() through you count number of file are there in specified folder. now in following example you can see "/var/www/test" in this folder, count how many files are there in that folder. glob function take a two argument first one for directory or folder path and second argument for filter. Filter means if you pass '*' then it will count all type of file, i mean all extension, but if you need to count just text file then you can put like '*.txt'. That't it, if in your directory, func.....

By Hardik Savani | February 4, 2016 | | 3959 Viewer | Category : PHP
READ MORE

How to find day from specific date in PHP?

Whenever you need to det day like Monday, Tuesday etc from full date. i mean you have any specific date like "2015-10-10" and you want to get day then you can do in both way first using strtotime() and second using DateTime object. In Following example you can see i give you both way to get day from your date. now i added format 'l' so it will return full name of day like "Tuesday", but if you want to get short name of day then you can change format like "D". <pre class="language-php"> // Using strtotime() $specificDate = strtotime('2016-2-3'); $specificDate = date('l', $specificDate); var_d.....

By Hardik Savani | February 3, 2016 | | 1121 Viewer | Category : PHP
READ MORE

How to check empty or null in Mysql Query?

If you want to check empty or null value with conditional statement like case when and if in table row with Mysql database. you like to check empty or null value form table then you have multiple way check that. first we check empty value with case when statement then following example. <strong>Empty Check:</strong> <pre class="language-mysql"> SELECT (CASE WHEN COALESCE(email,'')!='' THEN email ELSE 'example@gmail.com' END) as test FROM `customers` ---------------------OR---------------------- SELECT (CASE COALESCE(email,'') WHEN '' THEN 'example@gmail.com' ELSE email END) as test FR.....

By Hardik Savani | January 31, 2016 | | 1307 Viewer | Category : PHP
READ MORE

How to copy one table data into another table using Mysql Query?

If you are working on php or any php framwork and you want to copy one table into other table by using sql query, so you could do it using simple SELECT and INSERT statement. just you need to think how you can use. In Following example you can see how to fetch data from "post" table and how to insert into "post_copy" table, so basically you have to select field of one that you want to copy and second one give name of table with proper field that you want insert. But don't forgot to give a name of field otherwise it generate error. <pre class="language-mysql"> INSERT INTO `post_copy` (name,sl.....

By Hardik Savani | January 30, 2016 | | 3282 Viewer | Category : PHP
READ MORE

How to remove null values from array in PHP?

you have array with null value and you want to remove all null value from that array without loop. you can remove your all null value from array without loop. PHP array_filter function through you can remove all null value, you see following example how to remove null value : <strong>Example:</strong> <pre class="language-php"> $example = array(100, "hardik", null, "hey", NULL, "", 77); $result = array_filter($example, function($value) { return !is_null($value); }); print_r($result); </pre> <strong>Output:</strong> <pre>Array ( [0] => 100 [1] => hardik [3] => hey [5.....

By Hardik Savani | January 28, 2016 | | 3967 Viewer | Category : PHP
READ MORE

    Laravel 5.3 - Customize pagination templates example from scratch

    Laravel 5.3 - Customize pagination templates example from scratch

    Open Post

    Laravel 5 - Implement Flash Messages with example

    Laravel 5 - Implement Flash Messages with example

    Open Post

    PHP - How to convert HTML file to PDF using Dompdf library?

    PHP - How to convert HTML file to PDF using Dompdf library?

    Open Post

    Paypal payment gateway integration in php source code example

    Paypal payment gateway integration in php source code example

    Open Post

    Jquery - Animated typing effect using typed js example with demo

    Jquery - Animated typing effect using typed js example with demo

    Open Post

    PHP - How to implement Google new reCAPTCHA Code Example with Demo?

    PHP - How to implement Google new reCAPTCHA Code Example with Demo?

    Open Post