How to delete an element from a comma separated string using Javascript


var value = 1,2,3,4,5;

var remove_val = '3';

var separator = ",";

var new_value = value.split(separator);

for(var i = 0 ; i < new_value.length ; i++) {

if(new_value[i] == remove_val) {

new_value.splice(i, 1);

return new_value.join(separator);

}

}

Using more than one array in loop in PHP

Usually we use foreach loop when there is a need to use only one array. But what if there are more than one array…

Foreach loop works only with a single array. To step through multiple arrays it’s better to use the each() function in a while loop. Have a look at it..


while(($code = each($codes)) && ($name = each($names))) {
echo '<option value="' . $code['value'] . '">' . $name['value'] . '</option>';
}

each() returns information about the current key and value of the array and increments the internal pointer by one, or returns false if it has reached the end of the array. This code would not be dependent upon the two arrays having identical keys or having the same sort of elements. The loop terminates when one of the two arrays is finished.

Difference between == and === operator in PHP

When you want to compare values in PHP then you can use either == or === operator. But these both operator are not same. It’s good to know the difference between them.

These both operators fall under the category of Comparison Operators. The first operator ‘==’ is known as Equal Operator in PHP and checks for the equal values and the second operator ‘===’ is known as Identical Operator and checks for equal values and it also checks that if both the values are of same variable type or not.

How to remove index.php from url in CodeIgniter

Yes, you can remove the index.php from your url in your CodeIgniter web application.

You just need to add a .htaccess file in your web application folder.

Create a file and give it name .htaccess and save it in the root folder, and then copy the below block of code and paste it in the .htaccess file.


<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?/$1 [L]

</IfModule>

One more change you have to do in your config.php file.

Go to :

application/config/config.php

and remove index.php from $config[‘index_page’]

All Done. Enjoy!

How to add a line break in SMS Message

Sometimes while sending a SMS, we need to add a new line or a link break in our sms. There are many ways to add a line break. But now every method will work in your case because it depends on how you are sending your SMS.

I Method : 

Add “\r\n” in your SMS.

II Method : 

Add “%0a” in your SMS.

Note : Encode your message with ” ” (double quotes) not ‘ ‘ (single quotes).

Using PHP Array in Javascript

If you have a PHP Array and want to perform some javascript operations by looping the PHP Array, then I recommend you to use PHP foreach loop instead of Javascript forEach loop.


function myfunction() {

<?php foreach($myArray as $val) { ?>

console.log('<?=$val;?>');

<?php } ?>

}