Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8212041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:37:58+00:00 2026-06-07T10:37:58+00:00

I am working with CodeIgniter and have created a custom form preferences custom config.

  • 0

I am working with CodeIgniter and have created a custom form preferences custom config. In that I have an array that is as follows:

Array
(
  [1] => Category 1
  [2] => Category 2
  [3] => Category 3
  [4] => Category 4
  [5] => Category 5   
)

I am passing that to the view as the var $service_categories what I’d then like to do is match it to the “value” that is in the database. I.E 5. If it matches then show Category 5 in the view. At the moment I am just showing 5 – This is no good to the user.

The variable $service->service_category is a number.

The var service produces:

Array
(
    [0] => stdClass Object
    (
        [service_id] => 3
        [organisation_id] => 2
        [service_name] => Edited Service 3
        [service_description] => This is service 3 provided by
        [service_category] => 5
        [service_metadata] => Metadata for service 3 - Edited
        [service_cost] => 22.00
        [service_active] => active
    )
)

My current PHP for this is as follows:

if (in_array($service->service_category, $service_categories))
{
   echo "Exists";
}

However, the Exists is not showing in the view. It is showing nothing at all.

Am I doing something wrong with the in_array method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:38:00+00:00Added an answer on June 7, 2026 at 10:38 am

    in_array() checks if a value exists in the array. So in_array(‘Category 1’, $service_categories) would work.

    However, to check if a key is present in an array, you can use:

    if(array_key_exists($service->service_category, $service_categories)) {
        echo "Exists";
    }
    

    I think, this is what you’re looking for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a codeigniter code that is working on local Apache installation. But it
Okay so, I'm working with CodeIgniter. posts.php is my view that displays all the
I have a codeigniter form that contains two checkboxes: <input type=checkbox checked=checked id=box1 name=box1
I'm working on upgrading a Codeigniter app I have running on 1.7.2 to 2.0.3
I'm working on an app in CodeIgniter, and I want to have admin pages
i have start working with CodeIgniter, but i can't understand one think. How do
I am currently working with a codeigniter PHP based application and have come to
I have a codeigniter multistie install where I have such code that I can
I'm working on a new php project with CodeIgniter and I have few questions
I am using codeigniter 1.7.3 and I have controllers set up and working, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.