The ‘foreach’ loop can be used to multiple index variables of two arrays. This has been shown below −Example Live DemoOutputThis will produce the following output −aB12 PQ34 cd90 pm49Note − If there are more than 2 arrays, nested ‘foreach’ loops can be used.Here, 2 arrays have been declared and they are being traversed using the ‘foreach’ loop. The result is that the respective index of every array is matched and the data at those indices are displayed one next to the other.
The ‘preg_replace’ function can be used to match the characters in the string and remove the unnecessary characters.To keep letters and numbers −Example Live DemoOutputThis will produce the following output −Hello my name is Bobby I am 8 yearsTo keep letters only −Example Live DemoOutputThis will produce the following output −Hello my name is Bobby I am yearsTo keep letters, numbers and underscoreExampleOutputThis will produce the following output −Hello my name is Bobby I am 8 years
To detect base64 encoding in PHP, the code is as follows −Example Live Demo
The array_filter() or PREG_SPLIT_NO_EMPTY option on preg_split() can be used to remove empty values from a string when it is exploded −Example Live Demo
The fopen can’t be used to create directories. This is because fopen function doesn't create or open folders, it only works with files.Before using the fopen function, one should check with is_dir first if it exists, if not create it using the mkdir function −$filename = '/path/to /file.txt'; $dirname = dirname($filename); if (!is_dir($dirname)) { mkdir($dirname, 0755, true); }The above code creates a path to the file named ‘filename’. The directory of the ‘filename’ is obtained using the ‘dirname’ function. Next, this directory is checked for the existence using the ‘is_dir’ function. If the directory already exists, no operation takes ... Read More
The below code can be used to import CSV file in PHP −The file will display the contents of the csv file are displayed on the screen.In the above code, beginning from row 1 (since row 0 would usually contain headers/column names), the csv file is opened in read mode and the fgetcsv function is called to read in 1000 rows of data present in the csv file.The number of columns in every row is displayed along with the contents of it.
To check if a folder or a file is in use, the function is_dir() or is_file() can be used.The scandir function is an inbuilt function that returns an array of files and directories of a specific directory. It lists the files and directories present inside the path specified by the user.For example$scan = scandir('myFolder'); foreach($scan as $file) { if (!is_dir("myFolder/$file")) { echo $file.''; } }OutputList of files and directories inside the path specified (if any)The directory ‘myFolder’ is scanned using the ‘scandir’ function and the files and directories inside it are listed out. The ‘foreach’ ... Read More
When the backslash \ does not escape the terminating quote of the string or even create a valid escape sequence (in double quoted strings), then the below code can be used to produce one backslash −Example Live Demo$string = 'abc\def'; print($string);OutputThis will produce the following output −abc\defExample Live Demo$string = "abc\def"; print($string);OutputThis will produce the following output −abc\def
JShell has introduced in Java 9 and is a command-line tool that allows us to enter simple statements, expressions, methods, and classes without a main () method.When we can enter code in JShell, the code has assigned a unique ID. This ID starts at 1 and has incremented for each command entered in JShell. The same can be true for libraries loaded at startup. For each of these imports, a unique ID has been assigned. It starts with $1 and is incremented for each code loaded ($2, $3 and etc). There is an internal command to list all code loaded, and ... Read More
In OpenCV Mat class represents a matrix object which is used to store images. You can also declare a Mat object manually −Load the OpenCV native library − While writing Java code using OpenCV library, the first step you need to do is to load the native library of OpenCV using the loadLibrary().Instantiate the Mat class − Instantiate the Mat class using any of the functions mentioned in this chapter earlier.Fill the matrix using the methods − You can retrieve particular rows/columns of a matrix by passing index values to the methods row()/col().you can set values to these using any of ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP