How Pass PHP Array to Javascript

How Pass PHP Array to Javascript

The PHP array can be used in the javascript function in many ways. But today in this blog we will use the main two ways. The first one is json_encode() and the second one is most common PHP implode() function. Method 1 : json_encode() First, define an array into PHP. json_encode() returns the JSON representation … Read more

Find Longest, Shortest, and Random String in Array in Javascript


1. Find Longest String in Array Here I define an array list of six elements and we can see the Longest string is “Performance”. So run this script to get an answer. To Find the string we use reduce(). The reduce() the method executes a reducer function (that you provide) on each element of the array, resulting in a … Read more

How to Pass PHP Variable to JavaScript ?

Hello developer In this blog we will see how to access or use PHP variables in to Javascript. Sometime we need to just pass a PHP variable to Javascript on same page. So here simply set a variable value in PHP and we will use in show a alert in Javascript. HTML code In the … Read more

Image Preview Before Upload With Simple Javascript

This post describes how to preview an image before uploading it to the server by using javascript step by step. using FileReader and jquery. There are many methods to do this task. Some of them are through Jquery and some through pure JavaScript. So let’s start. Here is the result of the code Here is … Read more