-1

I have an array like this:

$descriptors = array(array ("science", "p1", "text"), array ("science, "p2", "more text")...array("Maths", "p1", "text"....)

I want to be able to get at the text for say the entry science, p2 - and I agree that the duplicate suggestion is useful, I don't think it works when you are looking to pull out one value for when there are many rows for each subject.

My question is 'how do I pull out 1 specific row which a particular value of subject and grade? Any ideas please

maxelcat
  • 1,333
  • 2
  • 18
  • 31

1 Answers1

2

Consider this example:

<?php
$descriptors = [
    'science' => [
        'p1' => 'text',
        'p2' => 'more text'
    ]
];
var_dump($descriptors['science']['p2']);

For an extremely old php version your'd have to use that variant:

<?php
$descriptors = array(
    'science' => array(
        'p1' => 'text',
        'p2' => 'more text'
    )
);
var_dump($descriptors['science']['p2']);

The output for both variants obviously is:

string(9) "more text"

And, BTW, PHP 4.12 is so old that most people don't even remember the syntax any more. Do yourself a favor and do upgrade to a current version. Alone the fact that this will close countless security issues should be worth the effort.

arkascha
  • 41,620
  • 7
  • 58
  • 90
  • yes, I know its old. I'll have to find out what is on the school's internal server and see if its possible. But thanks for the tip – maxelcat Mar 31 '16 at 09:24
  • This smells a bit as if the whole system did not receive any updates and fixes for many years. In that case it can only be called a huge security risk for your whole organization. You really want to take it offline NOW. – arkascha Mar 31 '16 at 09:26
  • Had a play with your answer - I think you have a much better way of arranging the array(s) - so I am going to rework into your suggestion. – maxelcat Mar 31 '16 at 09:46