I have got two associative arrays of different lengths. I want to know how to compare values and apply to checkboxes?How to sort an array of associative arrays by value of a given key in PHP?Codeigniter - Form validation converting post variables from Array to “Array” stringPHP foreach loop (output into CSS)Getting both or one Checkbox value in for each loophow to insert multiple values of array checkbox in one row with different field nameHow to assign values from associative array to check boxes using foreach in smarty?Is there any way to get ONLY the selects inputs from a form?Show checked=“checked” outside foreachbootstrap how to add/remove category just like opencart?Generate HTML to show custom questions with the correct type (text, checkbox, …) and add the required attribute properly
bldc motor, esc and battery draw, nominal vs peak
Who was the lone kid in the line of people at the lake at the end of Avengers: Endgame?
What term is being referred to with "reflected-sound-of-underground-spirits"?
How do I deal with a coworker that keeps asking to make small superficial changes to a report, and it is seriously triggering my anxiety?
Can SQL Server create collisions in system generated constraint names?
What are the steps to solving this definite integral?
Critique of timeline aesthetic
Mistake in years of experience in resume?
Relationship between strut and baselineskip
How to prevent z-fighting in OpenSCAD?
Why does nature favour the Laplacian?
Is there a way to generate a list of distinct numbers such that no two subsets ever have an equal sum?
Can an Area of Effect spell cast outside a Prismatic Wall extend inside it?
Dynamic SOQL query relationship with field visibility for Users
What does ゆーか mean?
How come there are so many candidates for the 2020 Democratic party presidential nomination?
Was there a Viking Exchange as well as a Columbian one?
How could Tony Stark make this in Endgame?
What's the polite way to say "I need to urinate"?
How would 10 generations of living underground change the human body?
Aligning equation numbers vertically
Don’t seats that recline flat defeat the purpose of having seatbelts?
Check if a string is entirely made of the same substring
Is there any official lore on the Far Realm?
I have got two associative arrays of different lengths. I want to know how to compare values and apply to checkboxes?
How to sort an array of associative arrays by value of a given key in PHP?Codeigniter - Form validation converting post variables from Array to “Array” stringPHP foreach loop (output into CSS)Getting both or one Checkbox value in for each loophow to insert multiple values of array checkbox in one row with different field nameHow to assign values from associative array to check boxes using foreach in smarty?Is there any way to get ONLY the selects inputs from a form?Show checked=“checked” outside foreachbootstrap how to add/remove category just like opencart?Generate HTML to show custom questions with the correct type (text, checkbox, …) and add the required attribute properly
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
There are two associative arrays of different lengths, how to compare their values and apply to checkboxes? If the values match, I need the checkbox gets the attribute checked.
Now I have this:
- Politics
- Video (Checked)
- Policy (Checked)
- Video
I want
- Video (Checked)
- Policy (Checked)
My code at the monent:
@foreach($category as $categories)
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]"> $categories->title
@foreach($post->category as $selected)
@if($selected->title == $categories->title)
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]" checked> $categories->title
@endif
@endforeach
@endforeach
php laravel
add a comment |
There are two associative arrays of different lengths, how to compare their values and apply to checkboxes? If the values match, I need the checkbox gets the attribute checked.
Now I have this:
- Politics
- Video (Checked)
- Policy (Checked)
- Video
I want
- Video (Checked)
- Policy (Checked)
My code at the monent:
@foreach($category as $categories)
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]"> $categories->title
@foreach($post->category as $selected)
@if($selected->title == $categories->title)
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]" checked> $categories->title
@endif
@endforeach
@endforeach
php laravel
You do have the result with you. No? Or do you want only checked boxes to show up?
– vivek_23
Mar 22 at 5:38
add a comment |
There are two associative arrays of different lengths, how to compare their values and apply to checkboxes? If the values match, I need the checkbox gets the attribute checked.
Now I have this:
- Politics
- Video (Checked)
- Policy (Checked)
- Video
I want
- Video (Checked)
- Policy (Checked)
My code at the monent:
@foreach($category as $categories)
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]"> $categories->title
@foreach($post->category as $selected)
@if($selected->title == $categories->title)
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]" checked> $categories->title
@endif
@endforeach
@endforeach
php laravel
There are two associative arrays of different lengths, how to compare their values and apply to checkboxes? If the values match, I need the checkbox gets the attribute checked.
Now I have this:
- Politics
- Video (Checked)
- Policy (Checked)
- Video
I want
- Video (Checked)
- Policy (Checked)
My code at the monent:
@foreach($category as $categories)
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]"> $categories->title
@foreach($post->category as $selected)
@if($selected->title == $categories->title)
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]" checked> $categories->title
@endif
@endforeach
@endforeach
php laravel
php laravel
edited Mar 22 at 5:45
Rahul Meshram
9,16442243
9,16442243
asked Mar 22 at 5:36
Alex SmirnovAlex Smirnov
14
14
You do have the result with you. No? Or do you want only checked boxes to show up?
– vivek_23
Mar 22 at 5:38
add a comment |
You do have the result with you. No? Or do you want only checked boxes to show up?
– vivek_23
Mar 22 at 5:38
You do have the result with you. No? Or do you want only checked boxes to show up?
– vivek_23
Mar 22 at 5:38
You do have the result with you. No? Or do you want only checked boxes to show up?
– vivek_23
Mar 22 at 5:38
add a comment |
2 Answers
2
active
oldest
votes
You can apply that condition inside element to apply checked property
@foreach($category as $categories)
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]"> $categories->title
@foreach($post->category as $selected)
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]" $selected->title == $categories->title ? 'checked' : ''> $categories->title
@endforeach
@endforeach
add a comment |
I have resolved this problem
Controller:
$checkedCategory = [];
foreach($post->category as $selected)
for($i = 0; $i < count($category); $i++)
if($selected->title == $category[$i]->title)
$checkedCategory[$i] = $category[$i]->title;
$checkedCategory = array_values(array_unique($checkedCategory, SORT_REGULAR));
Template:
<fieldset>
<legend>Категории</legend>
@foreach($category as $categories)
@if(in_array($categories->title, $checkedCategory))
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]" checked> $categories->title
@else
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]"> $categories->title
@endif
@endforeach
</fieldset>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55293474%2fi-have-got-two-associative-arrays-of-different-lengths-i-want-to-know-how-to-co%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can apply that condition inside element to apply checked property
@foreach($category as $categories)
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]"> $categories->title
@foreach($post->category as $selected)
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]" $selected->title == $categories->title ? 'checked' : ''> $categories->title
@endforeach
@endforeach
add a comment |
You can apply that condition inside element to apply checked property
@foreach($category as $categories)
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]"> $categories->title
@foreach($post->category as $selected)
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]" $selected->title == $categories->title ? 'checked' : ''> $categories->title
@endforeach
@endforeach
add a comment |
You can apply that condition inside element to apply checked property
@foreach($category as $categories)
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]"> $categories->title
@foreach($post->category as $selected)
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]" $selected->title == $categories->title ? 'checked' : ''> $categories->title
@endforeach
@endforeach
You can apply that condition inside element to apply checked property
@foreach($category as $categories)
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]"> $categories->title
@foreach($post->category as $selected)
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]" $selected->title == $categories->title ? 'checked' : ''> $categories->title
@endforeach
@endforeach
answered Mar 22 at 5:42
Rahul MeshramRahul Meshram
9,16442243
9,16442243
add a comment |
add a comment |
I have resolved this problem
Controller:
$checkedCategory = [];
foreach($post->category as $selected)
for($i = 0; $i < count($category); $i++)
if($selected->title == $category[$i]->title)
$checkedCategory[$i] = $category[$i]->title;
$checkedCategory = array_values(array_unique($checkedCategory, SORT_REGULAR));
Template:
<fieldset>
<legend>Категории</legend>
@foreach($category as $categories)
@if(in_array($categories->title, $checkedCategory))
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]" checked> $categories->title
@else
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]"> $categories->title
@endif
@endforeach
</fieldset>
add a comment |
I have resolved this problem
Controller:
$checkedCategory = [];
foreach($post->category as $selected)
for($i = 0; $i < count($category); $i++)
if($selected->title == $category[$i]->title)
$checkedCategory[$i] = $category[$i]->title;
$checkedCategory = array_values(array_unique($checkedCategory, SORT_REGULAR));
Template:
<fieldset>
<legend>Категории</legend>
@foreach($category as $categories)
@if(in_array($categories->title, $checkedCategory))
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]" checked> $categories->title
@else
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]"> $categories->title
@endif
@endforeach
</fieldset>
add a comment |
I have resolved this problem
Controller:
$checkedCategory = [];
foreach($post->category as $selected)
for($i = 0; $i < count($category); $i++)
if($selected->title == $category[$i]->title)
$checkedCategory[$i] = $category[$i]->title;
$checkedCategory = array_values(array_unique($checkedCategory, SORT_REGULAR));
Template:
<fieldset>
<legend>Категории</legend>
@foreach($category as $categories)
@if(in_array($categories->title, $checkedCategory))
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]" checked> $categories->title
@else
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]"> $categories->title
@endif
@endforeach
</fieldset>
I have resolved this problem
Controller:
$checkedCategory = [];
foreach($post->category as $selected)
for($i = 0; $i < count($category); $i++)
if($selected->title == $category[$i]->title)
$checkedCategory[$i] = $category[$i]->title;
$checkedCategory = array_values(array_unique($checkedCategory, SORT_REGULAR));
Template:
<fieldset>
<legend>Категории</legend>
@foreach($category as $categories)
@if(in_array($categories->title, $checkedCategory))
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]" checked> $categories->title
@else
<input type="checkbox" aria-label="$categories->title" value="$categories->title" name="category[$categories->id]"> $categories->title
@endif
@endforeach
</fieldset>
answered Mar 22 at 17:23
Alex SmirnovAlex Smirnov
14
14
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55293474%2fi-have-got-two-associative-arrays-of-different-lengths-i-want-to-know-how-to-co%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You do have the result with you. No? Or do you want only checked boxes to show up?
– vivek_23
Mar 22 at 5:38