Home » Search results for 'php array'

How to use the PHP parse_url() Function, With Examples

PHP parse_url

The PHP parse_url() function processes a given URL and divides it into its individual components.  Here’s how to use it. parse_url() is often used to get the host/domain name from a given URL or the path to a remote host file. Syntax for parse_url() parse_url ( $url , $component ) Note that: $url is the URL (e.g., https://www.linuxscrew.com) which you want to parse Relative URLs may not be parsed correctly $component is optional and can be one of: PHP_URL_SCHEME, PHP_URL_HOST, PHP_URL_PORT, PHP_URL_USER, PHP_URL_PASS, PHP_URL_PATH, PHP_URL_QUERY or PHP_URL_FRAGMENT … Read more

Categories PHP

Home » Search results for 'php array'

PHP isset() – Check if A Variable is Set, With Examples

Using PHP isset()

This article shows you how to use the PHP isset() function to check whether a variable exists and is populated. So, it’s checking if a variable is set. Why would you want to do this? You can’t perform actions on a variable that doesn’t exist or that has no value – you’ll either get unexpected output or an error. So, being able to check that a variable is set and is populated is pretty useful. Syntax for isset() isset ( $var1 , $var2…) Note that: $var1 should be … Read more

Categories PHP

Home » Search results for 'php array'

Looping over Array using JavaScript forEach(), With Examples

JavaScript foreach

This article will show you how to use the JavaScript forEach() method to loop over an array. Pretty much any application of any complexity will require the looping over arrays (lists) of data. The JavaScript forEach() method, which is built into JavaScript array variables, does just this. You’ll be using it a lot – so thankfully, it’s pretty darn easy to use. JavaScript forEach() Syntax arr.forEach(callback(currentValue[, index[, array]]) { // execute something }[, thisArg]); Note that: arr is an array or a variable containing an array callback is the … Read more

Home » Search results for 'php array'

PHP var_dump() Function [With Examples]

PHP var dump Function

The PHP programming language includes various built-in variable types and allows you to create your own complex object classes. Third-party packages also come with their own object classes. So it’s useful to find out what type of variable a variable is, its value, and the type/value of any properties or values the variable may contain. The PHP var_dump() function returns a given variable or value’s properties, including the value and type. It works through the variable’s properties or value recursively doing the same. Read on to learn … Read more

Categories PHP

Home » Search results for 'php array'

PHP foreach Loop [With Examples]

PHP foreach Loop

Looping over arrays and iterating over an object’s attributes form the foundation of a lot of application logic. The foreach construct in PHP can do both and is a crucial tool for building your application logic. PHP foreach Syntax The syntax for a foreach construct in PHP is as follows: foreach (iterable_expression as $value) { # statement(s) } Or, if you also wish to access the array key as well: foreach (iterable_expression as $key => $value) { # statement(s) } Note that: iterable_expression is the variable or value to … Read more

Categories PHP

Home » Search results for 'php array'

PHP switch Statement [With Examples]

PHP switch Statement

As you get more confident with your PHP code, your code will get more and more complex. The PHP switch statement simplifies your PHP logic, replacing messy if statements when trying to make simple decisions based on the value of a variable. Read on to find out how to use it. PHP switch Syntax switch($v) { case $a: # Code to be executed if $v is equal to $a break; case $b: # Code to be executed if $v is equal to $b break; case $c: # Code to … Read more

Categories PHP

Home » Search results for 'php array'

PHP ‘str_replace’ Function: Find and Replace Text

php str_replace function

The PHP str_replace() function replaces words or sections (known as substrings) in a string with other words or sentences, allowing you to modify or reformat text values (find and replace text). Syntax str_replace ( $search , $replace , $subject [, &$count ] ) Note that: $search is the string value being searched for – it can even be an array of strings if you wish to search for multiple values $replace is the value you wish to replace the $search value with – it can also be an array if … Read more

Categories PHP

Home » Search results for 'php array'

Using the PHP ‘explode’ Function (With Examples)

php explode function

PHP is one of the most popular programming languages used to develop web applications and APIs. Linux is the system of choice for serving up your PHP code and is also an ideal PHP development environment. The PHP explode function is vital for processing user input. It takes a string (a series of characters) and splits it up into smaller strings by a given delimiter to specify the boundary of where the splits should occur. Syntax explode ( $delimiter , $string [, $limit ] ) Note that: $delimiter … Read more

Categories PHP

Home » Search results for 'php array'

How to Read CSV Files in Python, With Examples

Python read from csv file

This article will show you how to read CSV (Comma Separated Values) files in the Python programming language, with examples. What is CSV (Comma Separated Values) CSV (Comma Separated Values) is a format for storing and transmitting data, usually in a text file, in which the individual values are separated by a comma (,). Each row in a CSV file represents an individual record containing multiple comma separated values. A CSV file looks like this: name,age,favourite colour Fred,54,green Mary,31,pink Steve,12,orange Above, the CSV describes three people, with information … Read more

Home » Search results for 'php array'

How to Sort a Dictionary by Value in Python [Examples]

Python sort dictionary by value

This article will show you how to sort a dictionary by the values it contains in the Python programming language. Code examples are included. What is a Dictionary? A dictionary is one of Pythons built in variable types for storing data. Dictionaries are similar to associative arrays or hash tables in other languages. A dictionary contains a collection of values or objects. Unlike lists and arrays, rather than their values being stored at a specific index (the ordered position in the sequence of stored values), values in a dictionary … Read more