All TalkersCode Topics

Follow TalkersCode On Social Media

Get Specific Key Value From Array PHP

Last Updated : Jan 1, 2023

Get Specific Key Value From Array PHP

In this tutorial we will show you the solution of get specific key value from array PHP, let us assume that there is a multidimensional array having approx.

5 rows and from them we have to get value of a key have 3rd place in 3 row.

So, how to done this, we are going to understand how to done this in php.

Step By Step Guide On Get Specific Key Value From Array PHP :-

Here, mainly there are many ways with help of which we are able to get specific key value from array in php.

This concept is easy to understand if we know about matrix. If not don’t worry we will show below a code in which we are going to get specific key value from array.

<!DOCTYPE html>
      <html>
        <head>
          <title>php generate unique id for mysql </title>
   </head>
 <body>
 <?php
 $array = array [
 [1,56,89,45,12,32],
 [56,85,02,45,37,40],
 [50,80,90,32,40,64],
 ]
 // let us assume that we have to get value of 2nd row and 4th column that is 45. Let us see how to do that.
$row= 1;
$col= 3;
foreach($array as $key => $value)
{
 if(isarray($value))
 {
 foreach($value as $key1 => $val)
 {
 echo $val[$row][$col];
 }
 }
}
 ?>
</body>
</html>
  1. First, we write <! DOCTYPE html> which we used as an instruction to the web browser about what version of HTML file is written in.
  2. Secondly, the <html> tag is used to indicate the beginning of an HTML document.
  3. As above now <head> tag is used to contain information about web page. In this tag a <title> tag is used which helps us to specify a webpage title. Both <head> and <title> tags are Paired tags. So, both have </head> and </title> ending tags respectively.
  4. Here, then we create a body tag. All the content which we want to show on browser’s screen or display is always written inside this codes.
  5. Here, as we see that inside body we create an array that is a multidimensional indexed array. We hope that you know the difference between indexed array, associative array and multidimensional array.
  6. Now, after that we say that we have to get the value 45 and we describe its positions. You can get the value of any key using the same method.
  7. Now, we use foreach loop, if you want to know more about foreach loop there is already an article on foreach from our side, you can visit to our article for more information.
  8. Now, at last we use echo to print the value which we want. Here, as we see that we already give the value of row and column there. Because we want to get the value of specific or say specified array.
  9. At last, the <body> and <html> tags are closed with </body> and </html> respectively.

Conclusion :-

At last in conclusion, here we can say that with the help of this article we are able to understand how to get specific key value from array php.

I hope this tutorial on get specific key value from array PHP helps you and the steps and method mentioned above are easy to follow and implement.

Latest Tutorials