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 467989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:38:14+00:00 2026-05-12T23:38:14+00:00

I am creating an array like this: function imageSize($name, $nr, $category){ $path = ‘ad_images/’.$category.’/’.$name.’.jpg’;

  • 0

I am creating an array like this:

function imageSize($name, $nr, $category){
    $path = 'ad_images/'.$category.'/'.$name.'.jpg';
    $path_thumb = 'ad_images/'.$category.'/thumbs/'.$name.'.jpg';
    list($width, $height) = getimagesize($path);
    list($thumb_width, $thumb_height) = getimagesize($path_thumb);
        $myarr = array();
    $myarr['thumb_image_' . $nr . '_width'] = $thumb_width;
    $myarr['thumb_image_' . $nr . '_height'] = $thumb_height;
    $myarr['image_' . $nr . '_width'] = $width;
    $myarr['image_' . $nr . '_height'] = $height;
    return $myarr;
}

I have hidden inputs on my page which values are taken from the array like this:
(FIRST)

<input type="hidden" id="img1_width" value="<?php echo $img_array['image_1_width'];?>" />
        <input type="hidden" id="img1_height" value="<?php echo $img_array['image_1_height'];?>" />
            <input type="hidden" id="img1_th_width" value="<?php echo $img_array['thumb_image_1_width'];?>" />
                <input type="hidden" id="img1_th_height" value="<?php echo $img_array['thumb_image_1_height'];?>" />

(SECOND)

<input type="hidden" id="img2_width" value="<?php echo $img_array['image_2_width'];?>" />
        <input type="hidden" id="img2_height" value="<?php echo $img_array['image_2_height'];?>" />
            <input type="hidden" id="img2_th_width" value="<?php echo $img_array['thumb_image_2_width'];?>" />
                <input type="hidden" id="img2_th_height" value="<?php echo $img_array['thumb_image_2_height'];?>" />

Now, if there is only 1 image, then the array will only be called ONCE, and the inputs which calls the second image (all inputs with ‘id’ = ‘img2 etc’) will have a value of undefined variable

My Q is this:
Is there any way I can check the array length and set the remaining values all to ‘0’ (zero) if they are not set?

Thanks

  • 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-05-12T23:38:14+00:00Added an answer on May 12, 2026 at 11:38 pm

    What if you loop through them…

    <?php for ($i=0;$i<count($array);$i++): ?>
    
    <input type="hidden" id="img{$i}_width" value="<?php echo $img_array["image_{$i}_width"];?>" />
    <input type="hidden" id="img{$i}_height" value="<?php echo $img_array["image_{$i}_height"];?>" />
    <input type="hidden" id="img{$i}_th_width" value="<?php echo $img_array["thumb_image_{$i}_width"];?>" />
    <input type="hidden" id="img{$i}_th_height" value="<?php echo $img_array["thumb_image_{$i}_height"];?>" />
    
    <?php endfor; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My system sends a configuration array to a function like this: callThatFunction( array(k1 =>
i want to output an array containing numbers. I'm creating the array like this
So I'm creating an array called fruits which I would like to share between
Creating a class with variables like this works fine : class Example { public
I have an array of folders/files that looks like this: Array ( [Root Folder
I'm creating my own JavaScript Array-like object and I have methods that call closures.
I try to make a generic function in C++, that creating an array of
I have 2 divs that I am creating from an array: $.each(data, function(i,item) {
function createPJOpportunityRelationship($pj_id, $op_id) { echo creating relationship; $set_relationship_value = array( 'module1' => 'geral_pessoa_juridica', 'module1_id'
Is there an already existing function in PHP for creating an associative array from

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.