Found 33676 Articles for Programming

Extract numbers after the last hyphen in PHP?

AmitDiwan
Updated on 20-Nov-2020 05:36:38

848 Views

Let’s say the following is our string including hyphen and numbers as well −"John-45-98-78-7898906756"To extract numbers after – i.e. hyphen, use the concept of explode() with parameters - and $yourVariableName.The PHP code is as follows −Example Live Demo Output7898906756

PHP How to cast variable to array?

AmitDiwan
Updated on 20-Nov-2020 05:35:37

643 Views

To cast variable to array, use the below syntax −$yourNewVariableName=(array)$yourVariableName;The PHP code is as follows −Example Live Demo OutputArray ( [0] => Mike [1] => Sam [2] => David )

PHP How to display array values with text “even” to be displayed for even index values

AmitDiwan
Updated on 20-Nov-2020 05:34:16

148 Views

For this, you can use for loop along with some conditions.The PHP code is as follows −Example Live Demo OutputEven 1 Even 3 EvenAbove, for 0th index, the text “Even” is displayed and the same goes on for 2th and 4th index.

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

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

243 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

128 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

503 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

95 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

Lonely Pixel I in C++

Arnab Chakraborty
Updated on 19-Nov-2020 10:17:47

225 Views

Suppose we have a picture consisting of black and white pixels, we have to find the number of black lonely pixels. Here the picture is represented by a 2D char array consisting of 'B' and 'W', for the black and white pixels respectively.A black lonely pixel is actually 'B' that located at a specific position where the same row and same column don't have any other black pixels.If the input is like −WWBWBWBWWOutput will be 3. Because all the three 'B's are black lonely pixels.To solve this, we will follow these steps −n := size of picturem := (if n ... Read More

Inorder Successor in BST II in C++

Arnab Chakraborty
Updated on 19-Nov-2020 10:15:29

387 Views

Suppose we have a node in a binary search tree, we have to find the in-order successor of that node in the BST. If there is no in-order successor, return null. As we know that the successor of a node is the node with the smallest key greater than value of node.We will have direct access to the node but not to the root of the tree. Here each node will have a reference to its parent node. Below is the definition for Node −class Node {    public int val;    public Node left;    public Node right;   ... Read More

The Maze II in C++

Arnab Chakraborty
Updated on 19-Nov-2020 10:13:27

540 Views

Suppose there is a ball in a maze with empty spaces and walls. Now the ball can go through empty paths by rolling any direction like up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, it could choose the next direction.We have to start position of ball, the destination and the maze, we have to find the shortest distance for the ball to stop at the destination. Here the distance is actually defined by the number of empty cells, that are covered by the ball (Excluding start position, including starting position). ... Read More

Advertisements