Found 1060 Articles for PHP

How to display array values with do while or for statement in my PHP?

AmitDiwan
Updated on 20-Nov-2020 05:32:52

242 Views

Following is the syntax to display array valuesdo{    //statement1    //statement2    .    .    .    n } while(yourCondition);The PHP code is as follows −Example Live Demo OutputJohn David Mike Sam Carol

What happens if ++ operator is used with string value in PHP?

AmitDiwan
Updated on 20-Nov-2020 05:31:22

126 Views

If you try to use ++ operator with string value then it increments the last character value with 1 and prints the ASCII value.Following is the PHP code −Example Live Demo OutputThe string modified value is=Joho The string incremented value is=11.5

strlen() php function giving the wrong length of unicode characters ?

AmitDiwan
Updated on 20-Nov-2020 05:30:04

500 Views

To get the correct length, use mb_strlen() for Unicode characters.The PHP code is as follows −Example Live DemoOutputThe string length with mb_strlen=9 The string length with strlen=10

PHP Why does this && not trigger as false?

AmitDiwan
Updated on 20-Nov-2020 05:27:49

94 Views

This is because if you use && both conditions must be true. If any one condition becomes false then the overall condition evaluates to false.The PHP code is as follows −Example Live Demo OutputThe above condition is true

CURL context options in PHP

Syed Javed
Updated on 13-Nov-2020 12:18:12

441 Views

IntroductionCURL context options are available when the CURL extension was compiled using the --with-curlwrappers configure option. Given below is list of CURL wrapper context optionsMethodDescriptionmethodHTTP method supported by the remote server. Defaults to GET.headerAdditional headers to be sent during requestuser_agentValue to send with User-Agent: header.contentAdditional data to be sent after the headers. This option is not used for GET or HEAD requests.proxyURI specifying address of proxy server.max_redirectsThe max number of redirects to follow. Defaults to 20.curl_verify_ssl_hostVerify the host. Defaults to FALSE. available for both http and ftp protocol wrappers.curl_verify_ssl_peerRequire verification of SSL certificate used. Defaults to FALSE. available for both ... Read More

The easiest way to concatenate two arrays in PHP?

AmitDiwan
Updated on 13-Oct-2020 08:50:40

3K+ Views

Simply use, array_merge() to concatenate two arrays in PHP. Let’s say the following are out arrays −$nameArray1 = array('John','David'); $nameArray2 = array('Mike','Sam');Now, set both the above arrays in array_merge() to concatenate them.The syntax is as follows −array_merge($yourFirstArrayName, $yourSecondArrayName);ExampleThe PHP code is as follows  Live Demo OutputThis will produce the following outputArray ( [0] => John [1] => David [2] => Mike [3] => Sam )

PHP make sure string has no whitespace?

AmitDiwan
Updated on 13-Oct-2020 08:48:42

3K+ Views

To check whether a string has no whitespace, use the preg_match() in PHP.The syntax is as follows preg_match('/\s/',$yourVariableName);ExampleThe PHP code is as follows Live Demo OutputThis will produce the following outputThe name (John Smith) has the space

How to add time in minutes in datetime string PHP?

AmitDiwan
Updated on 13-Oct-2020 08:46:42

11K+ Views

For this, you can use the strtotime() method.The syntax is as follows −$anyVariableName= strtotime('anyDateValue + X minute');You can put the integer value in place of X.ExampleThe PHP code is as follows Live Demo OutputThis will produce the following output2020-10-30 10:15:20

How to count values from a PHP array and show value only once in a foreach loop?

AmitDiwan
Updated on 13-Oct-2020 08:44:41

1K+ Views

Let’s say the following is our PHP array $listOfNames = array('John','David','Mike','David','Mike','David');We want the output to display the count of values in the above array like this −Array ( [John] => 1 [David] => 3 [Mike] => 2 )To get the count, use inbuilt function array_count_values().ExampleThe PHP code is as follows Live Demo OutputThis will produce the following outputArray ( [John] => 1 [David] => 3 [Mike] => 2 )

How to remove a character (‘’) in string array and display result in one string php?

AmitDiwan
Updated on 13-Oct-2020 08:41:18

319 Views

Let’s say the following is our string array −$full_name= '["John Doe","David Miller","Adam Smith"]';We want the output in a single string −John Doe, David Miller, Adam SmithFor this, use json_decode().ExampleThe PHP code is as follows Live Demo OutputThis will produce the following outputThe Result in one string=John Doe, David Miller, Adam Smith

Advertisements