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
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.
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.
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
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.
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
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
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
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
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