Wednesday, 17 April 2019

Passing php array into javascript variable


<?php
// php array
$fruits = array('apple', 'orange', 'mango', 'banana', 'strawberry');
?>

<script type="text/javascript">
// use php implode function to build string for JavaScript array literal
var fruits = <?php echo '["' . implode('", "', $fruits) . '"]' ?>;
// ["apple", "orange", "mango", "banana", "strawberry"]
</script>
source : 

https://www.dyn-web.com/tutorials/php-js/array.php

Tuesday, 16 April 2019

regex tester

script :

var paragraph = '222323';
var regex = '[0-9]{3,}'; //with at least 3 and above digits
var found = paragraph.match(regex);
console.log(found);
//which return back the array of numbers
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match

Postcode validation

https://stackoverflow.com/questions/17920096/php-validation-1st-line-of-address-and-postcode

Tuesday, 26 February 2019

Tuesday, 19 February 2019

Array Sorting based on key

foreach ($data as $key => $row) {
    $distance[$key] = $row['distance'];
}

array_multisort($distance, SORT_ASC, $data);
code to enable sorting for json feed/array.

source :
https://stackoverflow.com/questions/5305594/sort-a-multidimensional-array-using-array-multisort/5305641#5305641