Array Diff Key Functionality in PHP

AmitDiwan
Updated on 01-Jul-2020 08:39:46

161 Views

It is an inbuilt function that compares the keys of one or more arrays, and returns their difference.Syntax of the array_diff_key functionarray array_diff_key($array1, $array2, ..)The function can take two or more array names as parameters, and compares the first array with the remaining arrays.Example Live DemoOutputArray (    [91] => Micheal )Inside the tags, three arrays are declared with certain values in them. They are printed by calling the ‘array_diff_assoc’ function by passing all the three arrays to it as parameters. The resultant value is the different between the first array, and second array as well as the difference ... Read More

Significance of 'in' in PHP

AmitDiwan
Updated on 01-Jul-2020 08:37:23

416 Views

The ‘^’ is a bitwise operator in PHP, i.e XOR (exclusive OR) bitwise operator, that is used to display the ASCII values of variables in question. For example − For evert bit in the value, the ^ operator checks if that bit is the same in the other value too. If the values are same, 0 is produced as an output, otherwise 1 is shown as output. Below is an example illustrating the same −Example Live DemoOutputb aDifferent variables are assigned character values and the ‘^’ operator is used to perform XOR on the two variables. Relevant output is displayed on the console.

Delete Element from Array in PHP and Re-index the Array

AmitDiwan
Updated on 01-Jul-2020 08:35:38

2K+ Views

The ‘unset’ function can be used to remove an element from the array and use the ‘array_values’ function that resets the indices of the array.Example Live DemoOutputThe array is array(5) {    [0]=>    string(4) "this"    [1]=>    string(2) "is"    [2]=>    string(1) "a"    [3]=>    string(6) "sample"    [4]=>    string(4) "only" } The array is now array(4) {    [0]=>    string(4) "this"    [1]=>    string(2) "is"    [2]=>    string(1) "a"    [3]=>    string(6) "sample" }An array is declared that contains string values. The array is displayed and the ‘unset’ function is used to delete a specific index element from the array. Then the array is displayed again to reflect the changes on the console.

Find Standard Deviation of Values Within an Array in PHP

AmitDiwan
Updated on 01-Jul-2020 08:33:25

928 Views

To find standard deviation of values within an array, the code is as follows in PHP −Example Live DemoOutputThe standard deviation of elements in the array is 35.423156268181A function named ‘std_deviation’ is defined counts the number of elements in the array and initializes the variance to 0. The average is calculated as the sum of elements in the array divided by the total number of elements in the array. Now, a ‘foreach’ loop is run over the array and the variance is calculated by subtracted the average value from every element of the array and squaring it.When the foreach loop goes ... Read More

Find Missing Elements from an Array in PHP

AmitDiwan
Updated on 01-Jul-2020 08:32:02

1K+ Views

The ‘array_diff’ function can be used to find the elements that are missing from the array.Example Live DemoOutputElements missing from first array are Array (    [1] => 46    [2] => 47    [4] => 49    [5] => 50    [9] => 54    [10] => 55 ) Elements missing from second array are Array (    [1] => 100    [3] => 102    [4] => 103 )A function named ‘absent’ is defined that checks to see the minimum number and the maximum number and generates an array within that range. The function then returns the difference between this array and the original array, using the ‘array_diff’ function, that gives the missing elements from the array.

Remove Duplicate Elements from an Array in PHP

AmitDiwan
Updated on 01-Jul-2020 08:30:36

824 Views

The ‘array_flip’ function can be used, that will reverse the values as indices and keys as values.Example Live DemoOutputThe original array contains Array (    [0] => 45    [1] => 65    [2] => 67    [3] => 99    [4] => 81    [5] => 90    [6] => 99    [7] => 45    [8] => 68 ) The array after removing duplicate elements is Array (    [0] => 45    [1] => 65    [2] => 67    [3] => 99    [4] => 81    [5] => 90    [6] => 68 )An array ... Read More

Get Screen DPI Programmatically in Android

Azhar
Updated on 01-Jul-2020 08:24:22

1K+ Views

This example demonstrates how do I get screen DPI programatically in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.javaimport android.app.Activity; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.DisplayMetrics; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    Button button;    TextView textview;    float value = 0;    DisplayMetrics displaymetrics;    Activity activity;    @Override    protected void ... Read More

Format Date and Time in Android

Azhar
Updated on 01-Jul-2020 08:23:14

2K+ Views

This example demonstrates how do I format date and time in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.javaimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; import java.text.SimpleDateFormat; import java.util.Calendar; public class MainActivity extends AppCompatActivity {    TextView textView;    String dateTime;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       textView = findViewById(R.id.textView); ... Read More

Set Part of Android TextView as Clickable

Azhar
Updated on 01-Jul-2020 08:21:17

3K+ Views

This example demonstrates how do I set the part of the Android textView as clickable.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.javaimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.text.SpannableString; import android.text.Spanned; import android.text.method.LinkMovementMethod; import android.text.style.ClickableSpan; import android.view.View; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    TextView textView;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);     ... Read More

Display Toast Messages from a Thread in Android

Azhar
Updated on 01-Jul-2020 08:20:43

1K+ Views

This example demonstrates how do I display toast messages from a thread in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.javaimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    Toast toast;    Thread thread;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       toast = Toast.makeText(this, "This is a toast ... Read More

Advertisements