Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

How to fetch specific elements from an array and create a new array based on the comparison of an array key's value?

Course Queries Syllabus Queries
Max. 2000 characters
Replies

usr_profile.png
Alice Davidson

User

( 4 months ago )


My question may sound confusing to some people. But in fact it's a quite simple one. Let me clear you the scenario. I've an array titled $test_result_data as follows:

Array
(
    [0] => Array
        (
            [test_pack_id] => 8ed32f6479a0169db3531d3366996d35
            [test_pack_name] => CPT Free Samples
            [test_pack_desc] => This package contains a free sample test of 30 minutes containing 30 questions from - Fundamentals of accounting, Mercantile Law, General Economics and Quantitative Aptitude. This is perfect to discover the beauty of online exam preparation.
            [test_pack_type_id] => 7
            [test_pack_image] => 
            [test_pack_validity_year] => 0
            [test_pack_validity_month] => 0
            [test_pack_validity_days] => 3
            [test_pack_plan] => free
            [test_pack_price] => 0.00
            [test_pack_no_tests] => 0
            [test_pack_publish] => yes
            [test_pack_code] => 
            [test_pack_sold] => 22
            [test_pack_created_staff_id] => ff8d4a5ea6bf11dce105aa2fa7b959b8
            [test_pack_updated_staff_id] => ff8d4a5ea6bf11dce105aa2fa7b959b8
            [test_pack_created_date] => 1337014879
            [test_pack_updated_date] => 1376886700
            [test_pack_purchase_date] => 1364454118
            [test_details] => Array
                (
                    [0] => Array
                        (
                            [test_id] => 159
                            [test_name] => CPT Sample Test
                            [test_max_score] => 120.000
                            [test_no_questions] => 30
                            [test_attempt] => 15
                            [test_not_attempt] => 7
                            [avg_test_user_time_used] => 00:04:39 Hr
                            [top_score] => 46.00
                            [avg_score] => 3
                            [lower_score] => 0.00
                        )

                )

        )

    [1] => Array
        (
            [test_pack_id] => 84880f321fc957f9b28b702d5a43f57b
            [test_pack_name] => CPT General Economics
            [test_pack_desc] => This Package contains <b>16 chapterwise testlets
								 								 
							usr_profile.png
							
Amie Khalifa

User

( 4 months ago )

Use array_filter:

$filtered = array_filter($yourArray, function($element) use($test_pack_id) {
  return $element['test_pack_id'] == $test_pack_id;
});

what's your interest